老师好,请问一下这样写为何没反应?
来源:3-8 编程练习
慕尼黑4041527
2020-03-16 13:44:15
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>onblur和onfocus</title> <style type="text/css"> .red{ border:1px solid red; } .tip{display: none;} </style> </head> <body> 姓名:<input type="text"> <span class="tip">请输入您的姓名</span> <script type="text/javascript"> // 补充代码 var name=document.getElementsByTagName('input')[0], tip=document.getElementsByTagName('span')[0]; name.onfocus=function () { // body... tip.style.display="block"; } </script> </body> </html>
1回答
同学你好,因为window对象中也有name属性,变量设置为name会有冲突,所以没有反应。
建议:可以修改为其他变量,示例:
同学可以测试下,接着完善练习题了,祝学习愉快~
相似问题