如何仅在提交时执行验证-jQuery验证插件 [英] How to perform validation on submit only - jQuery Validation plugin

查看:71
本文介绍了如何仅在提交时执行验证-jQuery验证插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望jQuery Validate插件仅在提交表单时才显示验证消息,而不是在失去输入字段焦点时不显示验证消息.我如何做到这一点?

I want the jQuery Validate plugin to only display the validation messages only upon form submit and not when the focus from a input field is lost. How do Ii achieve this?

现在,我正在遵循此模式,该模式可在失去焦点事件后进行验证:

Right now I am following this pattern, which leads to validation after lost focus event:

<html>
<head>
 <script>
  $(document).ready(function(){
    $("#commentForm").validate();
  });
  </script>

</head>
<body>
<form class="cmxform" id="commentForm" method="get" action="">
 <fieldset>
<p>
     <label for="cname">Name</label>
     <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />
   </p>
</fieldset>
</form>
</body>
</html>

推荐答案

如果您希望在提交之前绝对不会收到任何错误,则需要禁用所有三个处理程序,并且可以执行如下验证:

You need to disable all three handlers if you wish to receive absolutely no errors before submission and you can do validation like this:

$('#commentForm').validate({
    onfocusout: false,
    onkeyup: false,
    onclick: false
})

这篇关于如何仅在提交时执行验证-jQuery验证插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆