【问题标题】:jquery validation error messages placementjquery 验证错误消息放置
【发布时间】:2014-01-13 13:05:49
【问题描述】:

我有一些带有不同错误消息的 span 元素。它们采用display:none 样式,我想将此属性更改为“内联”而不是显示错误消息。

这是我的规则

$().ready(function() {
 
 // validate signup form on keyup and submit
 $("#form").validate({
  rules: {
   telephone: {
    required: true,
    minlength: 9,
    maxlength: 9,
    number: true
   },
   email: {
    required: true,
    email: true
   }
      
  },
  messages: {
   telephone: {
    required: "The telephone is required",
    minlength: "The must have at least 9 digits"
   },
   email: "Please enter a valid email"
   });
});

我的 span 元素如下所示:

<span id="telephoneerror" class="infoerror" style="display:none">The telephone is required</span>
<span id="telephonelenghterror" class="infoerror" style="display:none">The must have at least 9 digits</span>

我是 jQuery 的初学者。

谢谢。

【问题讨论】:

  • $('#telephoneerror').css('display','inline');
  • 而here 是完整文档的链接。
  • 感谢 Morteza Edalati,我在发布之前一直在查看文档,但我不知道在哪里添加此代码。

标签: jquery validation properties html


【解决方案1】:

你有不同的方法来做到这一点

  1. 添加类

    $('#telephoneerror').addClass('myclass');

  2. 属性

    $('#telephoneerror').attr('style','display:inline-block');

  3. css

    $('#telephoneerror').css('display','inline-block');

【讨论】:

  • 谢谢...但我不知道应该在哪里添加代码。我试图写它而不是消息部分,但它不起作用:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多