例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>