clientX 事件屬性
定義和用法
clientX 事件屬性返回當(dāng)事件被觸發(fā)時鼠標(biāo)指針向?qū)τ跒g覽器頁面(或客戶區(qū))的水平坐標(biāo)。
客戶區(qū)指的是當(dāng)前窗口。
語法
event.clientX
提示和注釋
注釋:2 級 DOM 沒有提供把窗口坐標(biāo)轉(zhuǎn)換為文檔坐標(biāo)的標(biāo)準(zhǔn)方法。在 IE 以外的瀏覽器,使用 window.pageXOffset 和 window.pageYOffset 即可。
實例
下面的例子可顯示出事件發(fā)生時鼠標(biāo)指針的坐標(biāo):
<html> <head> <script type="text/javascript"> function show_coords(event) { x=event.clientX
y=event.clientY
alert("X coords: " + x + ", Y coords: " + y) } </script> </head> <body onmousedown="show_coords(event)"> <p>Click in the document. An alert box will alert the x and y coordinates of the mouse pointer.</p> </body> </html>
TIY
- clientX
- 顯示鼠標(biāo)指針的坐標(biāo)。