求高手看一下这个代码,调试了很久都拖曳不了
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{margin:0;padding:0;} ul{position: absolute;left: 30px;top: 50px;} li{list-style: none;margin-top: 5px;} #login_box{width:300px;height:150px;background:#eee; border:1px solid #ccc;position:absolute;left:50%;top:50%;margin-left:-150px;margin-top:-75px;} #login_box p{height:20px;border-bottom:1px solid #ccc;font-size:12px;padding:6px 0 0 5px;font-weight:bold;} #close{width:14px;height:14px;background:url(http://icon.mobanwang.com/UploadFiles_8971/200805/20080528160815283.png) no-repeat;position:absolute;right:4px;top:6px;} </style> <script> window.onload=drag; function drag(){ var otitle=document.getElementsByTagName('p'); otitle.onmousedown=fndown(); } function fndown(event){ event=event||window.event; var box=document.getElementById("login_box"); var disX=event.cilentX-box.offsetLeft; var disY=event.cilentY-box.offsetTop; document.onmousemove=function(event){ event=event||window.event; fnmove(event,disX,disY);} document.onmouseup=function)(){ document.onmousemove=null; } } function fnmove(event,px,py){ var box=document.getElementById("login_box"); var l=event.clientX-px; var t=event.clientY-py; var clientW=document.documentElement.clientWidth||document.body.clientWidth; var clientH=document.documentElement.clientHeight||document.body.clientHeight; var maxl=clientW-box.offsetWidth; var maxt=clientH-box.offsetHeight; if (l<0) { l=0; } else if(l>maxl) { l=maxl; } if (t<0) { t=0; } else if(t>maxt) { t=maxt; } box.style.left=l+'px'; box.style.top=t+'px'; } </script> </head> <body> <div id="login_box"> <p>用户登录</p><span id="close"></span> <ul> <li>用户名 <input type="text" name="username"><li/> <li> 密码 <input type="text" name="password"><li/> </ul> </div> </body> </html>
一直都无法点住p标签后拖曳整个框,不知道哪里有问题