如何使用jQuery Validator添加错误消息

问题描述 投票:0回答:1

我得到了我的“联系我”表单,我正在使用验证,但我无法弄清楚如何显示错误消息。我试过阅读文档,但我只是不明白如何使用errorPlacement函数。有人可以告诉我一个如何用我得到的代码做一个例子吗?

<fieldset>
    <input placeholder="Ditt navn" name="contact_name"  id="contact_name" class="contact_input" type="text"  tabindex="1" required autofocus>
</fieldset>
<fieldset>
    <input placeholder="Din email adresse" name="contact_mail" id="contact_mail"  class="contact_input"  type="email" tabindex="2" required>
</fieldset>
<fieldset>
    <input placeholder="Firma navn (valgfri)" name="contact_firmname" id="contact_firmname"  class="contact_input" type="text" tabindex="3">
</fieldset>


$(document).ready(function(){
    $('body').on('keyup','#contact_me',function(){
      $('#contact_me').validate({
        rules: {
          contact_name: {
            required: true,
            remote: location.protocol + '//' + location.host+'/ajax_contact.php'
          },
          contact_mail: {
            required: true,
            remote: location.protocol + '//' + location.host+'/ajax_contact.php'
          },
          contact_firmname: {
          },
        },
        errorPlacement: function(){
            return false;
        },
        submitHandler: function (form) {
          return false;
        }
     });
   });
});
jquery html css
1个回答
0
投票

如果你不知道如何做某事,不要卡在文档上。相反,寻找一个例子,通常1000倍清晰。

本文展示了您在代码中尝试重现的可测试示例:https://www.webcodegeeks.com/javascript/jquery/jquery-errorplacement-example/

© www.soinside.com 2019 - 2024. All rights reserved.