Разметка:
<input type="text" name="email" />
Код:
$(':text').focusout(function(){
$(this).validate(function(){
$(this).attr('name');
});
});
Плагин:
(function($){
$.fn.validate = function(type) {
return this.each(function(type) {
if (type == 'email') {
matches = this.val().match('/.+@.+\..{2,7}/');
(matches != null) ? alert('valid') : alert('invalid');
}
/*else if (type == 'name') {
}
else if (type == 'age') {
}
else if (type == 'text') {
}*/
else {
alert('total failure');
}
});
};
})(jQuery);
Проблема заключается в том, что когда я выполняю код выше, он запускаетПлагин, как если бы тип был строкой: "function () {$ (this) .attr ('name');});"вместо того, чтобы выполнять его как функцию.Как мне это решить?