我想將一些函數和變量實現到mootools的Element成員中。我有這樣的事情Mootools Element.prototype error
Element.prototype.currentChild = this.getFirst();
Element.prototype.scrollToNext = function(delta, tag){ .... }
後,我創建一個新的元素和鼠標滾輪事件綁定到跨度和存取權限是currentChild。
body_container = new Element('div', {
events:{
'mousewheel': function(e){
var elem = new Element(this);
elem.currentChild.setStyle('background-color', 'transparent');
elem.scrollToNext(e.wheel);
elem.currentChild.setStyle('background-color', '#C6E2FF');
e.stop();
}
}
});
的問題是,我得到以下錯誤:
Uncaught TypeError: Object [object Window] has no method 'getFirst'
你知道什麼可能會導致這樣? LE:是的,我期待'this'是一個元素。但我不明白爲什麼它會是Window類型。
你有什麼期待'this'是在這裏:*'Element.prototype.currentChild = this.getFirst();'* – Esailija 2012-07-30 19:18:16
嗯,這顯然是一個'Window'對象而不是預期的「元素」。 – TheZ 2012-07-30 19:18:22