jquery验证.rules()验证有效,但是没有显示消息?

时间:2015-10-20 01:21:48

标签: jquery jquery-validate

对于以下输入字段...

<input type="text" value="" name="registerModel.Name" id="registerModel_Name" placeholder="Your display name" class="form-control" aria-required="true">

...我添加了一个简单的验证规则:

$('input[name="registerModel.Name"]').rules('add', {
        required: true,
        messages: {
            required: "Required input"
        }
    });

验证有效,当我点击表单的提交按钮时,它不发送:

<input type="text" value="" name="registerModel.Name" id="registerModel_Name" placeholder="Your display name" class="form-control input-validation-error" aria-required="true" aria-describedby="registerModel_Name-error" aria-invalid="true">

但不显示错误消息。

它是一种引导形式,但我在过去没有遇到jquery验证和引导程序的任何问题。

我非常感谢你。

<form method="post" enctype="multipart/form-data" action="/" id="formvalidatemember" novalidate="novalidate">
    <div class="form-group">
         <label class="form-control-label col-sm-3" for="registerModel_Name">Your name</label>
         <div class="col-sm-9">
            <input type="text" value="" name="registerModel.Name" id="registerModel_Name" placeholder="Your display name" class="form-control" aria-required="true">
         </div>
    </div>
    <div class="col-sm-offset-3 col-sm-9">
       <button class="btn btn-secondary buttonSendForm" type="submit">Register</button>
     </div>
</form>

$(function () {
 $("#formvalidatemember").validate();
 $('#registerModel_Name').rules('add', {
  required: true,
  minlength: 6,
  messages: {
   required: "Required input",
   minlength: jQuery.validator.format("Please, at least {0} characters are necessary")
  }
 });
});

1 个答案:

答案 0 :(得分:-1)

我将jquery验证升级到最新版本,现在它可以工作了。很抱歉。