Javascript 如何使用jquery在不同的按钮单击中验证同一表单
Javascript 如何使用jquery在不同的按钮单击中验证同一表单,javascript,jquery,Javascript,Jquery,edit txt,updatePassword是一种形式的两个按钮superAdminDetailsForm。我想在两个按钮点击中验证此表单。我在每次点击按钮时都写下了表单验证,但它不起作用。编辑txt按钮为文本类型,更新密码为按钮类型 $().ready(function() {$('#edit-txt').on('click', function() { $("#superAdminDetailsForm").validate({
edit txt
,updatePassword
是一种形式的两个按钮superAdminDetailsForm。我想在两个按钮点击中验证此表单。我在每次点击按钮时都写下了表单验证,但它不起作用。编辑txt按钮为文本类型,更新密码为按钮类型
$().ready(function() {$('#edit-txt').on('click', function() {
$("#superAdminDetailsForm").validate({
rules: {
superadminEmail:{
required:true,
email:true
},
},
messages: {
superadminEmail:"Please enter your Email id"
},
submitHandler: function(){
var formData =$("#superAdminDetailsForm").serialize();
$.ajax({
url:'/accounts',
type:'post',
datatype: 'json',
data: formData,
success : function(response){
if(response == "true"){
window.location='/accounts';
} else {
alert("false")
}
},
error: function (request,status, error) {
}
});
return false;
}
});
});
$('#updatePassword').on('click', function() {$("#superAdminDetailsForm").validate({
rules: {
oldPassword:"required",
newPassword:"required",
confirmpassword:{
require :"true",
equalTo : "#oldPassword"
}
},
messages: {
oldPassword:"Please enter Old Password ",
newPassword: "Please enter New Password",
confirmpassword:"Retype password is incorrect"
},
submitHandler: function(){//to pass all data of a form serial
var formData =$("#superAdminDetailsForm").serialize();
$.ajax({
url:'/changePassword',
type:'post',
datatype: 'json',
data: formData,
success : function(response){
if(response == "true"){
window.location = '/accounts';
} else {
alert("password incorrect");
}
},
error: function (request,status, error) {
}
});
return false;
}
});
});
});