Posted in Javascript onJanuary 07, 2009
<html xmlns="http://www.w3.org/1999/xhtml" >
<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>
通用JS事件写法实现代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@