例1:
<Script>
function getEvent(evnt) {
eventWin = open ('','','width=200,height=100');
with (eventWin.document) {
write("事件类型:", event.type);
write("<br>鼠标的x坐标:", event.screenX);
write("<br>鼠标的y坐标:", event.screenY);
}
}
document.write ("单击...")
document.onmousedown = getEvent;
</Script>
例2:
<Script>
function getCoordinate(evnt) {
if (document.all) {
x = event.screenX;
y = event.screenY;
}
else {
x = evnt.screenX;
y = evnt.screenY;
}
status = "水平坐标:"+ x + ";垂直坐标:"+ y;
}
document.onmousemove = getCoordinate;
</Script>
例3:
<Script>
function whichKey(evnt) {
if (document.all) {
x = event.button;
if( x==1 ) alert("你单击了左键");
if( x==2 ) alert("你单击了右键");
}
else {
x = evnt.button;
if( x==1 ) alert("你单击了左键");
if( x==3 ) alert("你单击了右键");
return false;
}
}
document.onmousedown = whichKey;
document.write("请单击鼠标左/右键");
</Script>