My jQuery plugin always return Object object
I am writing a jQuery plugin but it is always returning Object object here is the code inside:
$.fn.plugin = function(options) {
var defaults = {
rules : []
}
var options = $.extend(defaults, options);
return this.each(function() {
var o = options;
var rules = o.rules;
var i=0;
var isValable = true;
var string = "";
for (i=0;i<=((rules.length)-1);i++)
{
$('.'+rules[i][0]).each(function(index) {
var val = $(this).val();
var $elm = $(this);
if(!(rules[i][2](val, $elm)))
{
if (!$elm.hasClass('validation-failed')) $elm.addClass('validation-failed');
$elm.after('<div class="validation-advice" id="advice-' + rules[i][0] + '-' + $elm.attr('id') +'" style="display:none">' + rules[i][1] +开发者_如何转开发 '</div>');
isValable = false;
}
else if (!$elm.hasClass('validation-passed')) $elm.addClass('validation-passed') ;
});
}
return isValable;
});
}
I get the Object object when calling alert($('myselector').plugin())
Thanks for your help
not sure if it's the problem because you didn't show how you're calling the plugin but it should be
return $(this).each(function()...
I had problems because of the double return, removing the first one solved it !
精彩评论