87,922
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
//绑定事件的函数:
/**
* @description 事件绑定,兼容各浏览器
* @param target 事件触发对象
* @param type 事件
* @param func 事件处理函数
*/
function addEvents(target, type, func) {
if (target.addEventListener) //非ie 和ie9
target.addEventListener(type, func, false);
else
if (target.attachEvent) //ie6到ie8
target.attachEvent("on" + type, func);
else
target["on" + type] = func; //ie5
};
//删除事件的函数:
/**
* @description 事件移除,兼容各浏览器
* @param target 事件触发对象
* @param type 事件
* @param func 事件处理函数
*/
function removeEvents(target, type, func){
if (target.removeEventListener)
target.removeEventListener(type, func, false);
else
if (target.detachEvent)
target.detachEvent("on" + type, func);
else
target["on" + type] = null;
};
var f1=function(){alert('41');}
var f2=function(){alert('42');}
addEvents(b4,"click",f1); //绑定事件的函数,b4是按钮id
addEvents(b4,"click",f2); //绑定事件的函数,b4是按钮id
removeEvents(b4,"click",f1);//删除事件的函数,b4是按钮id
</script>