[英]jquery plugin doesn't recognize calling parameters
我已經創建了一個插件,並設置了默認值,但是當我更改調用腳本中的參數時,它們不會得到反映,默認值始終優先。 我在這里想念什么?
我的.html文件中的調用腳本
$('.inputBox').validate(function() {
rounded: true
});
精簡的插件。 即使我在第一個代碼段中將四舍五入設置為true,但在firebug中將其記錄到控制台時,它始終為false。 為什么是這樣?
(function($) {
$.fn.validate = function(options) {
var
defaults = {
rounded: false
},
settings = $.extend({}, defaults, options);
$(this).each(function(index) {
if(settings.rounded) {
$(this).addClass('roundedMsg');
}
});
return this;
};
})(jQuery);
您不需要將函數傳遞給插件,而需要傳遞對象:
$('.inputBox').validate({
rounded: true
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.