首页 > 编程 > JavaScript > 正文

javascript 一个函数对同一元素的多个事件响应

2019-11-21 01:14:45
字体:
来源:转载
供稿:网友
复制代码 代码如下:

var testButton=document.getElementById("testButton");
function handlerTest()
{
var oEvent=window.event;//for IE
//var oEvent=arguments[0];// for DOM
if(oEvent.type=="click")
{
alert("click");
}
else if(oEvent.type=="mouseover")
{
alert("mouseover");
}
else
{
alert(oEvent.keycode);
}
}
testButton.onclick=handlerTest;
testButton.onmouseover=handlerTest;

html元素如下:<input id="testButton" type="button" value="testButton" />
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表