screenX 事件屬性
定義和用法
screenX 事件屬性可返回事件發生時鼠標指針相對於屏幕的水平坐標。
語法
event.screenX
實例
實例
下面的例子可顯示出事件發生時鼠標指針的坐標:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script type="text/javascript">
function coordinates(event){
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
在文檔中點擊某個位置。 消息框會提示出指針相對於屏幕的x 和y 坐標。
</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script type="text/javascript">
function coordinates(event){
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
在文檔中點擊某個位置。 消息框會提示出指針相對於屏幕的x 和y 坐標。
</p>
</body>
</html>
嘗試一下»
事件對象