jquery验证,当输入字段具有标题属性时,而不是错误消息标题作为错误消息给出

前端之家收集整理的这篇文章主要介绍了jquery验证,当输入字段具有标题属性时,而不是错误消息标题作为错误消息给出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我正在使用 jquery验证插件.

我有一个奇怪的问题,我有一个这样的有效性

  1. jQuery("#profile_info").validate({
  2.  
  3. rules : {
  4. city : {
  5. required : true,minlength : 3,maxlength : 30,cityvalidation: true
  6. },state : {
  7. required : true,cityvalidation: true
  8. }
  9. },messages : {
  10. city : {
  11. required : " City must be filled in",minlength : "At least 3 characters long",maxlength : "Should not exceed 30 characters",},state : {
  12. required : " State must be filled in",}
  13. }
  14. });

和城市验证

  1. jQuery.validator.addMethod("cityvalidation",function(value,element) {
  2. return this.optional(element) || /^[a-zA-Z\u0080-\u024F\s\/\-\)\(\`\.\"\']+$/i.test(jQuery.trim(value));
  3. },"You Have Typed Unallowed Charactors");

我的输入字段是

  1. <div class="select-date-container-side location-codes">
  2. <input id="city" name="city"
  3. value="<?PHP if(isset($profileinfo['CityName'])){echo $profileinfo['CityName'];}else if(isset($city)){echo $city;} ?>"
  4. title="City" type="text"
  5. class="smaler-textfield textfield clear-default"
  6. tabindex="1900" />
  7. </div>
  8. <div class="select-date-container-middle location-codes">
  9. <input id="state" name="state"
  10. value="<?PHP if(isset($profileinfo['StateName'])){echo $profileinfo['StateName'];}else if(isset($state)){echo $state;} ?>"
  11. title="State" type="text"
  12. class="smaler-textfield textfield clear-default"
  13. tabindex="1900" />
  14. </div>

如果城市验证失败. “你已经键入不允许的Charactors”消息,而不是显示字段的标题.

>如果我删除标题,它的工作完美.所以我假装做了我想得到自定义错误信息而不是标题.请帮忙……..

提前致谢 …………………

解决方法

嗯我发现了.

我用了ignoreTitle:true,

  1. jQuery("#profile_info").validate({
  2.  
  3.  
  4. ignoreTitle: true,rules : {
  5. city : {
  6. required : true,}
  7. }
  8. });

猜你在找的jQuery相关文章