复制代码 代码如下: 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" />
推荐阅读
JavaScript 动态生成方法的例子
复制代码 代码如下:function User(properties){ for(var i in properties){ //遍历该对象的所有属性,并保证其作用于正确 (function(which){ var p=i; which["get"+p]=function(){ //动态生成的方法 return proper>>>详细阅读
本文标题:javascript 一个函数对同一元素的多个事件响应
地址:http://www.17bianji.com/kaifa2/JS/28380.html
1/2 1