0
這是我第一次創建插件。但是我的插件有一些小問題。我創建了我的插件簡單翻版低於用ajax創建jquery插件
$.fn.myPlugin = function(url){
return this.each(function() {
element = $(this);
$.getJSON(url, function(response){
elem.val(response.init_value);
});
});
}
,並開始喜歡這個
$("#test1").myPlugin('/get1.json'); //this should value 1
$("#test2").myPlugin('/get2.json'); //this should value 2
,但如預期的結果是不工作
Element #test1 has done nothing, no value (I think it is broken)
Element #test2 has value of 2
我的插件工作正常,當我啓動一個單一的實例,但當我試圖做出多個實例時,只有最後一個實例正在工作。
OMG。那是它?謝謝vi5ion!你節省了我的一天。 –