javascript 一个函数对同一元素的多个事件响应
(编辑:jimmy 日期: 2025/5/13 浏览:3 次 )
复制代码 代码如下:
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" />
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" />
下一篇:IE中radio 或checkbox的checked属性初始状态下不能选中显示问题