jQuery .validate initial label text

房东的猫 提交于 2019-12-12 05:38:16

问题


hi i was wondering how can i make for once the field is validate to show initial text in label:

jQuery:

$("#contact").validate({
  rules: {
    con_name: {
      required:true,
      minlength:3
    },
  }  
});

HTML:

<form id="contact" method="post" action="">
    <input type="text" name="con_name" id="con_name" />
    <label for="con_name" generated="true" class="error">Insert Name</label>
</form>

The text Insert Name is replaced with the error message but upon success it hides the label and erases the initial text Insert Name. I need it to show again the initial text.


回答1:


Set the messages like I show:

Set like this:

$("#contact").validate(
    {       
    rules:{
        con_name:{required:true, minlength:3},                      
          }  
    messages: {
          con_name: 'Insert Name'
          }

    });


来源:https://stackoverflow.com/questions/12203208/jquery-validate-initial-label-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!