代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
//本程序通过点击鼠标输出光标的 相对浏览器的坐标 和相对屏幕的坐标
function getXY(event){
var butNum = event.button;
var a = event.screenX; var b = event.screenY;
var x = event.clientX; var y = event.clientY;
if(butNum == 0){
alert("光标的坐标是:("+x+","+y+")");
}else if(butNum == 1){
alert("相对于屏幕,光标的坐标是:["+a+","+b+"]");
}else if(butNum == 2){
alert("光标的坐标是:("+x+","+y+")"+"\n相对于屏幕,光标的坐标是:["+a+","+b+"]");
}
}
</script>
</head>
<body onmousedown="getXY(event)">
get point
</body>
</html>