萝卜头IT论坛

搜索
查看: 4777|回复: 1
收起左侧

js中教你获取鼠标坐标

[复制链接]
发表于 2012-8-4 08:51:06 | 显示全部楼层 |阅读模式
本帖最后由 杏阳 于 2012-8-4 08:53 编辑

移动鼠标,可以在第二个框,和鼠标的下方产生当前页面鼠标位置的坐标,点击回车就会将现在的鼠标位置的坐标显示出来
<html>

<head>

<script language="javascript" type="text/javascript">
<!--

function fun1(){
  var t1=document.getElementById("txt1");

  e=window.event;
  x=e.clientX;
  y=e.clientY;
  t1.value="x坐标="+x+" y坐标="+y;
  
}

function fun2(){
    var t2=document.getElementById("txt2");
    var div=document.getElementById("div1");
    e=window.event;
    x=e.clientX;
    y=e.clientY;
    t2.value="x坐标="+x+" y坐标="+y;
    div.innerHTML="<p>x:" + x + " y:" + y + "</p>";
    div.style.left=x+5;
    div.style.top=y+15;
}

function fun3(){
}
//-->
</script>
</head>

<body>
定点坐标 <input type=text id="txt1"/>
动点坐标<input type=text id="txt2"/>
<div id="div1" style="position:absolute"></div>
</body>

</html>

11_11_01.html
http://kuai.xunlei.com/d/OSHJJCSSDENQ
回复

使用道具 举报

发表于 2012-8-4 16:34:52 | 显示全部楼层
恩,不错
回复

使用道具 举报

联系我们(Contact)|手机版|萝卜头IT论坛 ( 苏ICP备15050961号-1 )

GMT+8, 2024-3-29 16:02 , Processed in 0.102106 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表