如何將我的綁定方法轉換爲允許單個對象或對象數組(在這種情況下爲多個鏈接)將函數綁定到某些事件?會很酷的bind()方法,我認爲內處理它。任何幫助,將不勝感激單個對象或對象數組的綁定方法?
var dQuery = function() {
return {
bind: function(obj, type, handler, delegate) {
var delegate = delegate || false;
this.log(obj);
if (obj.addEventListener) {
obj.addEventListener(type, handler, delegate); // false: bubble (^). true: capture (v).
} else if (obj.attachEvent) {
obj.attachEvent('on'+ type, handler);
} else {
obj['on'+ type] = handler;
}
}
}
}();
(function($){
var $links = document.getElementsByTagName('a');
$.bind($links, 'click', function() {
// .. do stuff to each <a>
});
})(dQuery);
注:在它的當前狀態,它只能處理 – tester 2010-09-15 19:04:20