|
<head>
<title>test</title>
<script language="Javascript" type="text/Javascript">
window.onload = function()
{
var oImg = document.getElementById("myImg");
oImg.onclick = handle;
oImg.onmouseover = handle;
}
function handle(oEvent)
{
var oDiv = document.getElementById("display");
//處理瀏覽器兼容性,獲得事件對象
if(window.event) //判斷是否為IE瀏覽器
{
oEvent = window.event;
}
if(oEvent.type == "click")
{
oDiv.innerHTML += "點擊<br>";
}
if(oEvent.type == "mouseover")
{
oDiv.innerHTML += "移動<br>";
}
}
</script>
</head>
<body>
<img id="myImg" src="test.gif" />
<div id="display"></div>
</body>
</html>
JavaScript技術:通用JS事件寫法實現代碼,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。