JS部分onmousedown不起作用,大家?guī)兔纯?/h1>
<!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>
就是鼠標(biāo)不用按下去,窗口都會(huì)跟著鼠標(biāo)走
<!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>
就是鼠標(biāo)不用按下去,窗口都會(huì)跟著鼠標(biāo)走
2016-08-05
login.onmousedown=fndown();錯(cuò)了
應(yīng)該是 login.onmousedown=fndown; ? ? // 加括號(hào)調(diào)用一次,就會(huì)觸發(fā)document事件