简体   繁体   English

在div元素内找出鼠标位置?

[英]inside div element find out mouse position?

i done one concept of program is find out mouse coordinate position inside div element ... its perfectly working in IE browser only but i cant get answer in mozilla firefox... what is the reason?????????? 我完成了一个程序概念,就是找出div元素内的鼠标坐标位置...仅在IE浏览器中完美运行,但是我无法在mozilla firefox中得到答案...是什么原因?

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Cursor position status display</title>
<script type="text/javascript">

 function getXOffset(e){
if(typeof e.offsetX != 'undefined')
  return e.offsetX;
 else if(typeof e.pageX != 'undefined')
  return e.pageX - e.target.offsetLeft;
}

function getYOffset(e){
 if(typeof e.offsetY != 'undefined')
  return e.offsetY;
   else if(typeof e.pageY != 'undefined')
  return e.pageY - e.target.offsetTop;
}

function displayOffsets(e){
e = (e) ? e : window.event;
window.status = 'x: '+getXOffset(e)+'   y: '+getYOffset(e); 
}

 </script>
 </head>
 <body>
  <div style="width:100px; height:300px;margin:50px 0 0 500px;border:1px solid red;" >
  <div onMouseMove="displayOffsets(event)" style="width:50px; height:300px;     background:#669966;"></div>
  <div >
  </body>
   </html>

Your function may be working perfectly fine, your problem is probably the window.status part: https://developer.mozilla.org/en/DOM/window.status 您的功能可能工作得很好,您的问题可能是window.status部分: https : //developer.mozilla.org/en/DOM/window.status

This property does not work in default configuration of Firefox and some other browsers: setting window.status has no effect on the text displayed in the status bar. 此属性在Firefox和某些其他浏览器的默认配置中不起作用:设置window.status对状态栏中显示的文本无效。

Maybe try outputing the coordinates into some other element in the page, or better yet, if you have something like Firebug, you can output use the console . 也许尝试将坐标输出到页面中的其他元素,或者更好的是,如果您有Firebug之类的东西,则可以使用控制台输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM