开发者

jquery plugin doesn't recognize calling parameters

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜