<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="/UploadFiles/2021-04-02/test.gif"><div id="display"></div>
</body>
</html>
标签:
JS,事件

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
评论“通用JS事件写法实现代码”
暂无“通用JS事件写法实现代码”评论...