0
我試圖做一個jQuery插件使用引導類。jquery和使用預定義的函數
(function($) {
$.fn.bsalert = function(klass, condition, hdr, msg) {
if (condition) {
this.html('<strong>' + hdr + '!</strong> ' + msg);
this.addClass(klass);
} else {
this.html("");
}
};
$.fn.bssuccess = function(condition, hdr, msg) {
//How to read a selector????
$(selector???????).bsalert("alert alert-success", condition, hdr, msg);
};
$.fn.bswarning = function(condition, hdr, msg) {
$(selector???????).bsalert("alert alert-warning", condition, hdr, msg);
};
})(jQuery);
,我試圖用這樣的:
$("#successmsg").bssuccess(error==="","OK","you've done");
$("#errormsg").bswarning(error!=="","Error",error);
我如何讀取內部函數定義選擇?
只需使用'this'來代替'selector ???????' – Satpal
您的意思是您想要調用'bssuccess'函數的元素的選擇符?如果是這樣,你可以在插件中使用'this'來獲取元素本身。 –
謝謝你的提示。謝謝,蒂爾溫錯誤修復。 – user2301515