DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js移除事件 js綁定事件實例應用
js移除事件 js綁定事件實例應用
編輯:關於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;
};
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved