例1:
<Script>
function getEvent(evnt) {
eventWin = open ('','','width=200,height=100');
with (eventWin.document) {
write("事件類型:", event.type);
write("<br>鼠標(biāo)的x坐標(biāo):", event.screenX);
write("<br>鼠標(biāo)的y坐標(biāo):", 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 = "水平坐標(biāo):"+ x + ";垂直坐標(biāo):"+ 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("請(qǐng)單擊鼠標(biāo)左/右鍵");
</Script>