亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript gets mouse coordinates

Mouse coordinates include x coordinates, y coordinates, coordinates relative to the client, coordinates relative to the screen, etc.

In JavaScript, mouse coordinates exist as attributes of the event object.

The properties related to mouse coordinates in the event object are as follows.

QQ截圖20161013101054.png

QQ截圖20161013101100.png

Get the coordinate information of the mouse.

<html>
<head>
<title>獲取鼠標(biāo)的坐標(biāo)信息</title>
</head>
<body>
<div id="demo">點(diǎn)擊這里</div>
<script type="text/javascript">
document.getElementById("demo").onclick=function(e){
    var eve = e || window.event;
    var x = eve.clientX,  // 相對于客戶端的X坐標(biāo)
        y = eve.clientY,  // 相對于客戶端的Y坐標(biāo)
        x1 = eve.screenX,  // 相對于計(jì)算機(jī)屏幕的X坐標(biāo)
        y1 = eve.screenY;  // 相對于計(jì)算機(jī)屏幕的Y坐標(biāo)
        
    alert(
        "相對客戶端的坐標(biāo):\n"+
        "x = "+x+"\n"+
        "y = "+y+"\n\n"+
        "相對屏幕的坐標(biāo):\n"+
        "x = "+x1+"\n"+
        "y = "+y1
    );
}
</script>
</body>
</html>


Continuing Learning
||
<html> <head> <title>獲取鼠標(biāo)的坐標(biāo)信息</title> </head> <body> <div id="demo">點(diǎn)擊這里</div> <script type="text/javascript"> document.getElementById("demo").onclick=function(e){ var eve = e || window.event; var x = eve.clientX, // 相對于客戶端的X坐標(biāo) y = eve.clientY, // 相對于客戶端的Y坐標(biāo) x1 = eve.screenX, // 相對于計(jì)算機(jī)屏幕的X坐標(biāo) y1 = eve.screenY; // 相對于計(jì)算機(jī)屏幕的Y坐標(biāo) alert( "相對客戶端的坐標(biāo):\n"+ "x = "+x+"\n"+ "y = "+y+"\n\n"+ "相對屏幕的坐標(biāo):\n"+ "x = "+x1+"\n"+ "y = "+y1 ); } </script> </body> </html>
submitReset Code