1
我有這個奇怪的問題,其中我的jQuery插件的其他實例得到修改,即使我相信我已經編寫了我的插件來支持多個單獨的實例。另一個jQuery插件實例被重寫的屬性
我已經剝離下來的代碼,以最基本的要素,你可以在這裏測試一下:http://jsbin.com/ajifoh/4/edit#html,live
第一次按下任意文本框的關鍵應該在控制檯中顯示leng: 0
,但經過你由於某種原因,第一個觸發了第一個,還有第一個插入的所有comboPart ...我做錯了什麼?
;(function($, window, document, undefined){
var KeyCombinator = function(elem, options){
this.$elem = $(elem);
};
function ComboPart(keyCode){
if (keyCode !== undefined){
this.keyCode = keyCode;
}
}
function ComboData(){
this.comboParts= [];
}
function set_insert(array, value){
array.push(value);
}
KeyCombinator.prototype = {
comboData: new ComboData(),
eval_key_event: function(e){
set_insert(this.comboData.comboParts, new ComboPart(e.keyCode));
},
init: function(){
var $elem = this.$elem;
var that = this;
$elem.keydown(function(e){
console.log('leng', that.comboData.comboParts.length);
that.eval_key_event(e);
});
}
};
$.fn.makeKeyCombinator = function(options) {
return this.each(function() {
new KeyCombinator(this, options).init();
});
};
})(jQuery, window, document);