<!doctype html> <html> <head> <style> #text{display:block;width:300px;cursor:pointer;height:20px;border:solid 1px #CCC;} #menu{display:none;width:300px;height:100px;border:solid 1px #CCC;} </style> <meta charset="utf-8"> <title>无标题文档</title> </head> <body> <span id="text">点击显示菜单,再点击隐藏菜单</span> <div id="menu">这是文字哦。</div> <script type="text/javascript"> window.onload=function(){ var wenzi=document.getElementById("text"); var div=document.getElementById("menu"); wenzi.onfocus=function(){ if(div.style.display=='block'){ // == 判断div.display是否为显示 div.style.display='none'; //= 赋值也可了解成改变 } else{ div.style.display='block'; } } } </script> </body> </html>
_追梦的少年_
相关分类