获取鼠标坐标

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <head>
  3.    <title>Mouse co-ordinates</title>
  4.    <style type="text/CSS">
  5.       .holder {background-color:lightyellow;color:blue;width:40}
  6.    </style>
  7. <script type="text/javascript">
  8. function showit()
  9. {
  10.    document.forms['theform'].xcoord.value=event.x;
  11.    document.getElementById('spanx').innerHTML='x='+event.x;
  12.    document.forms.theform.ycoord.value=event.y;
  13.    document.getElementById('spany').innerHTML='y='+event.y;
  14. }
  15. function showitMOZ(e)
  16. {
  17.    document.forms['theform'].xcoord.value=e.pageX;
  18.    document.getElementById('spanx').innerHTML='x='+e.pageX;
  19.    document.getElementById('spany').innerHTML='y='+e.pageY;
  20.    document.forms.theform.ycoord.value=e.pageY;
  21. }
  22. if (!document.all){
  23. window.captureEvents(Event.CLICK);
  24. window.onclick=showitMOZ;
  25. }
  26. else
  27. {
  28. document.onclick=showit;
  29. }
  30. </script>
  31. </head>
  32. <body>
  33. <br><br><br>
  34. <h1>You can store them in form fields</h1>
  35. <form name="theform">
  36.   x = <input name="xcoord" style="width:40">
  37. y = <input name="ycoord" style="width:40">
  38. </form>
  39. <br /><br />
  40. <h1> or as plain text</h1>
  41. <span id="spanx"> </span>
  42. <span id="spany"> </span>
  43. </body>
  44. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值