亲宝软件园·资讯

展开

通用JS事件写法实现代码

人气:0
<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>

加载全部内容

相关教程
猜你喜欢
用户评论