如何使 Jquery 表单验证函数在其他函数之前执行/触发?
我使用 Jquery 表单验证来验证表单输入数据。有一个
确认
检查
提交 这种形式的。 .
代码是:
<script type="text/javascript">
function Confirmation(){
var answer = confirm("Do you really want to withdraw this amount of money from your account?")
if (answer){
return true;
}
else{
return false;
}
}
$(document).ready(function() {
$("#withdraw").validate({
rules: {
amount: {
required: true,
digits:true
} ,
bank:{
required:true,
},
cardnumber1: {
required: true,
minlength:8
},
cardnumber2:{
required:true,
equalTo: "#cardnumber1"
},
holder:{
required:true,
}
}
})
});
</script>
我想在Confirmation()
之前执行Jquery表单验证,该怎么做?
I use Jquery form validation to validate form input data. There is a
confirm
check on
submit
of this form.
.
The code is:
<script type="text/javascript">
function Confirmation(){
var answer = confirm("Do you really want to withdraw this amount of money from your account?")
if (answer){
return true;
}
else{
return false;
}
}
$(document).ready(function() {
$("#withdraw").validate({
rules: {
amount: {
required: true,
digits:true
} ,
bank:{
required:true,
},
cardnumber1: {
required: true,
minlength:8
},
cardnumber2:{
required:true,
equalTo: "#cardnumber1"
},
holder:{
required:true,
}
}
})
});
</script>
I want the Jquery form validation is executed before the Confirmation()
, how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Steven,
您需要从表单中删除
onsubmit
处理程序,并将其添加到验证插件的submitHandler
中......Steven,
You need to remove the
onsubmit
handler from the form and add it the thesubmitHandler
of the validate plugin ...我查看了文档,有一个名为submitHandler的选项,我认为它会允许您在提交表单之前但在验证发生之后添加确认对话框。试试这个...
I looked at the documentation and there is an option named submitHandler which I think would allow you to add your confirmation dialog before the form is submitted but after the validation happens. Try this...