日期:2014-05-16 浏览次数:20443 次
<html>
<head>
<title>事件类型</title>
<script type="text/javascript">
function testEvent(oEvent){
var oText = document.getElementById("textId");
oText.value += "\n"+oEvent.type;
}
</script>
</head>
<body>
<div style="width: 100px; height: 100px; background-color: red;"
onclick="testEvent(event);" ondblclick="testEvent(event);" onmouseover="testEvent(event);"
onmousedown="testEvent(event);" onmousemove="testEvent(event);"
onmouseout="testEvent(event);" onmouseup="testEvent(event);" >
</div>
<br/>
<textarea id="textId" rows="30" cols="100"></textarea>
<br/>
</body>
</html><html>
<head>
<title>事件类型</title>
<script type="text/javascript">
function testEvent(oEvent){
var oText = document.getElementById("textId");
oText.value += "\n"+oEvent.type;
oText.value += "\n at("+oEvent.clientX+","+oEvent.clientY+") 客户端浏览器坐标 ";
oText.value += "\n at("+oEvent.screenX+","+oEvent.screenY+") 屏幕坐标 ";
oText.value += "\n button down is "+oEvent.button;
var keys = [];
if(oEvent.shiftKey){
keys.push("Shift");
}
if(oEvent.ctrlKey){
keys.push("Ctrl");
}
if(oEvent.altKey){
keys.push("Alt");
}
oText.value += "\n keys down are " +keys;
}
</script>
</head>
<body>
<div style="width: 100px; height: 100px; background-color: red;"
onclick="testEvent(event);" ondblclick="testEvent(event);" onmouseover="testEvent(event);"
onmousedown="testEvent(event);" onmousemove="testEvent(event);"
onmouseout="testEvent(event);" onmouseup="testEvent(event);" >
</div>
<br/>
<textarea id="textId" rows="30" cols="100"></textarea>
<br/>
</body>
</html>这些属性都给出刚刚发生的鼠标事件的一些信息。