JS部分onmousedown不起作用,大家帮忙看看
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #box{ width: 400px; height: 250px; background-color: #F0FFFF; border: solid cornflowerblue; top: 200px; left: 300px; position: absolute; } #login{ width: 400px; height: 30px; border-bottom: solid cornflowerblue; background-color: cornflowerblue; margin-top:-18px; } #login p{ text-align: center; color:#F0FFFF; font-weight:900; font-size: large; } </style> <script type="text/javascript"> window.onload=drag; function drag(){ var login=document.getElementById("login").childNodes[0]; login.onmousedown=fndown(); } function fndown(){ document.onmousemove=function(event){ var box=document.getElementById("box"); box.style.left=event.clientX+'px'; box.style.top=event.clientY+'px'; } } </script> </head> <body> <div id="box"> <div id="login"><p>登录</p></div> </div> </body> </html>
就是鼠标不用按下去,窗口都会跟着鼠标走