<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <style type="text/css"> #div1{width:200px;height:30px;background-color:red;} #div2{width:150px; height:20px;background-color:gray;margin-top:10px;display:none;} </style> <script type="text/javascript"> window.onload = function () { var div1 = document.getElementById("div1"); var div2 = document.getElementById("div2"); var timer = null; function show() { div2.style.display = "block"; clearTimeout(timer); } function hide() { timer = setTimeout(function () { div2.style.display = "none"; }, 300); } div1.onmouseover = show; div1.onmouseout = hide; div2.onmouseover = show; div2.onmouseout = hide; } </script> </head> <body> <div id="div1"></div> <div id="div2"></div> </body> </html>
div1.onmouseover = show; div1.onmouseout = hide; div2.onmouseover = show; div2.onmouseout = hide;为啥我要是写成div1.onmouseover = show(); div1.onmouseout = hide(); div2.onmouseover = show(); div2.onmouseout = hide();就不行呢?函数的调用不得加上后面的括号吗?求解答
慕无忌8876879
相关分类