HTML代码
<form id="RegisterForm">
<div class="login-screen">
<div class="login-form">
<div class="form-group">
<p>账号</p>
<input type="text" name="UserCode" class="form-control login-field" value="" placeholder="Enter Your Code" id="UserCode">
<p id="UserCodeP"></p>
</div>
<div class="form-group">
<p>密码</p>
<input type="password" name="Password" class="form-control login-field" value="" placeholder="Password" id="Password">
</div>
<div class="form-group">
<p>确认密码</p>
<input type="password" name="ConfirmPassword" class="form-control login-field" value="" placeholder="Confirm Password" id="ConfirmPassword">
</div>
<button class="btn btn-primary btn-lg btn-block" οnclick="Register_Index.RegisterSubmit()">Register</button>
</div>
</div></form>
js代码
var Register_Index = function() {
return {
RegisterSubmit: registerSubmit,
}
function formValidate() {
$("#RegisterForm").validate({
rules: {
UserCode: "required",
Password: "required",
ConfirmPassword: "required"
},
messages: {
UserCode: "请输入账号",
Password: "请输入密码",
ConfirmPassword: "请输入确认密码"
}
});
}
function registerSubmit() {
formValidate();
var formValidateIsTrueOrFalse = $("form").valid();
if (formValidateIsTrueOrFalse) {
$.ajax( {
type : "POST",
url: "/Register/UserRegister",
data: $("#RegisterForm").serialize(),
success: function () {
}
});
}
}
}();
标签:Jquery,function,required,formValidate,UserCode,验证,Register,密码,Validate
From: https://blog.51cto.com/u_16082658/6249895