我想將我的插件附加到輸入字段,並且它有點作用。因此,我將on()
和onchange
附加到輸入字段,並且當它觸發時,會觸發每個輸入,而不僅僅是發生更改的輸入。這是什麼造成的?是因爲我使用$(document).on()
嗎?我是這樣添加的,因爲項目會動態地添加到頁面中。事件會觸發所有項目,而不僅僅是當前項目
(function($){
$.fn.itemsave = function(config){
return this.each(function(){
var item = $(this);
var opt = {
// The options
};
var e = $.extend(opt, config);
$(document).on("change", item, function(){
request(false, e);
});
});
})(jQuery);
它是怎樣叫:
$(".simplesave").itemsave(null);
當使用jQuery變量時,應該使用特殊符號:var $ item = $(this)。它會避免混淆 – Sigismundus 2015-04-01 21:55:06