欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js移除事件 js綁定事件實(shí)例應(yīng)用

 更新時(shí)間:2012年11月28日 10:20:30   作者:  
本文將詳細(xì)介紹js移除事件 js綁定事件的實(shí)現(xiàn)過程,需要了解的朋友可以參考下
復(fù)制代碼 代碼如下:

/**
* @description 事件綁定,兼容各瀏覽器
* @param target 事件觸發(fā)對(duì)象
* @param type 事件
* @param func 事件處理函數(shù)
*/
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
};

復(fù)制代碼 代碼如下:

/**
* @description 事件移除,兼容各瀏覽器
* @param target 事件觸發(fā)對(duì)象
* @param type 事件
* @param func 事件處理函數(shù)
*/
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;
};

相關(guān)文章

最新評(píng)論