通用JS事件写法实现代码
程序员文章站
2022-06-29 09:04:58
<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>
<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>
上一篇: 你知道怎么做炖鸡吗
下一篇: 孕妇喝红糖好吗,今天介绍给你