jquery中的this对象:
this对象,如果在全局变量中表示的是windows对象
在局部变量中,表示的是这个函数的所有者,也就是谁绑定了这个函数,谁就是这个this对象
表单的验证模板
以register.js外部文件为例:
// 页面加载函数
$(function(){
error_name=false;
error_pwd=false;
error_cpwd=false;
error_phone=false;
error_email=false;
$("selector").blur(function(){
check_name();
});
$("selector").blur(function(){
check_pwd();
});
$("selector").blur(function(){
check_cpwd();
});
$("selector").blur(function(){
check_phone();
});
$("selector").blur(function(){
check_email();
});
// 验证姓名
function check_name(){
...
}
// 验证密码
function check_pwd(){
...
}
// 验证确认密码
function check_cpwd(){
...
}
// 验证手机号
function check_phone(){
...
}
// 验证邮箱
function check_email(){
...
}
// 用于最后是否提交数据
$("selector").submit(function(){
if(error_name==false && error_pwd==false && error_cpwd==false && error_phone==false && error_email==false){
$("selector").submit();
return true;
}else{
console.log('输入有误')
return false;
}
});
});
小白光原创,有什么错误或者问题,请指教 微信:zq521686