JS得到鼠标当前位置

<html>
<head>
<script language=”javascript” type=”text/javascript”>
<!–
var domType = ”;
if (document.all) {
domType = “ie4”;
} else if (document.getElementById) {
domType = “std”;
} else if (document.layers) {
domType = “ns4”;
}
function initMouseMove(){
if(!document.all){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = mouseMove;
}
function mouseMove(e){
var x,y;
if(!document.all){
fetch_object(“txt”).value=”move”;
x=e.pageX;
y=e.pageY;
}else{
x=document.body.scrollLeft+event.clientX;
y=document.body.scrollTop+event.clientY;
}
fetch_object(“txt”).value=x+”:”+y;
}
var objects=new Array();

function fetch_object(idname, forcefetch) {
if (forcefetch || typeof(objects[idname]) == “undefined”) {
switch (domType) {
case “std”: {
objects[idname] = document.getElementById(idname);
}
break;

case “ie4”: {
objects[idname] = document.all[idname];
}
break;

case “ns4″: {
objects[idname] = document.layers[idname];
}
break;
}
}
return objects[idname];
}
–>
</script>
<title>get mouse position</title>
</head>
<body onload=”initMouseMove()”>
<input id=”txt”/>
</body>
</html>

发表评论

电子邮件地址不会被公开。 必填项已用*标注