日期:2014-05-16  浏览次数:20344 次

我想在获取鼠标位置时,使div随着鼠标而动。
<script   language= "javascript "   type= "text/javascript ">
function   m(evt){
  document.getElementById( "area ").innerHTML=evt.clientX   + "   ,   "+evt.clientY;
  p.style.top=evt.clientX   ;//我想在这里使div "p "的位置在鼠标的位置
}
</script>
<div   id= "area "   style= "font-size:36px;width:800px;height:600px;border:1px   solid; "   onmousemove= "m(event); "> d </div>
<div   id= "p "> <span> 11111111 </span> </div>

------解决方案--------------------
<script language= "javascript " type= "text/javascript ">
function m(evt){
document.getElementById( "area ").innerHTML=evt.clientX + " , "+evt.clientY;
p.style.left=evt.clientX;
p.style.top=evt.clientY;//我想在这里使div "p "的位置在鼠标的位置
}
</script>
<div id= "area " style= "font-size:36px;width:800px;height:600px;border:1px solid; " onmousemove= "m(event); "> d </div>
<div id= "p " style= "position:absolute; "> <span> 11111111 </span> </div>