我觉得我在用下面的代码呼叫功能不工作
我试图调用双向的功能,但这么想的工作第二种方式this
元素一个问题:
函数validate_email没有响应,我想在第二个例子中调用它是错误的。
的工作方式是:
checking = {};
checking.form = function(){
return{
validate_mail: function(a){
var c=true;
var email_filter = /^[\w.-][email protected][\w.-]+([\.]+([\w]+[\.])?)+[a-zA-Z]{2,6}$/i;
if($.trim(a)!="" && !$.trim(a).match(email_filter))
c=false;
return c;
},
check_mail: function(div_id, error) {
var email = $(div_id + ' input[name=email]').val();
var check = this.validate_mail(email);
if(check==false && $(div_id).is(':visible'))
{
$(div_id + ' '+ error).html('<b>some error</b>');
} else {
$(div_id + ' ' + error).text('');
}
}
}
}();
$(function(){
$('#register input[name=email]').blur(function(){
checking.form.check_mail("#register", ".error_email");
});
}
的不工作的方式是:
checking = {};
checking.form = function(){
return{
validate_mail: function(a){
var c=true;
var email_filter = /^[\w.-][email protected][\w.-]+([\.]+([\w]+[\.])?)+[a-zA-Z]{2,6}$/i;
if($.trim(a)!="" && !$.trim(a).match(email_filter))
c=false;
return c;
},
check_mail: function(div_id, error) {
return function(){ //**made the change nr. 1**
var email = $(div_id + ' input[name=email]').val();
var check = this.validate_mail(email);
if(check==false && $(div_id).is(':visible'))
{
$(div_id + ' '+ error).html('<b>some error</b>');
} else {
$(div_id + ' ' + error).text('');
}
}
}
}
}();
$(function(){ //**made the change nr. 2**
$('#register input[name=email]').blur(
checking.form.check_mail("#register", ".error_email")
);
}
我需要一些帮助与此有关。我相信我没有正确使用this
元素
任何帮助表示赞赏!
究竟是不是工作? – Stefan 2012-01-05 21:28:10
如果我们甚至不知道代码应该做什么以及想要做什么,我们如何能够帮助您? – 2012-01-05 21:29:06
函数validate_email没有响应,我认为在第二个例子中调用它是错误的 – sorin 2012-01-05 21:31:31