开发者

jquery plugin doesn't recognize calling parameters

开发者 https://www.devze.com 2022-12-20 07:02 出处:网络
I\'ve created a plugin and I have my defaults set but when I change the parameters in the calling script, they are not reflected, the defaults are always taking precedence. What am i missing here?

I've created a plugin and I have my defaults set but when I change the parameters in the calling script, they are not reflected, the defaults are always taking precedence. What am i missing here?

calling script in my .html file

$('.inputBox').validate(function() {
    rounded: true
});

Stripped down plugin. Even though i'm setting rounded to true in the first snippet, it's always false whe开发者_C百科n i log it to the console in firebug. Why is this?

(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);


You don't need to pass a function to the plugin, you need to pass an object:

$('.inputBox').validate({
    rounded: true
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号