【问题标题】:jQuery Validate error positioning for fields with position absolutejQuery验证具有绝对位置的字段的错误定位
【发布时间】:2011-02-11 04:34:35
【问题描述】:

我有一个以图像为背景的 div,输入字段的位置已在图像中设置。 结果,在 html 标记中,我将字段的位置设置为绝对位置,以便它们覆盖在图像上。 我遇到的问题是,当使用 jquery validate 插件时,错误消息显示在顶部。我不知道如何在字段右侧显示它。

这是代码片段:

<div id="user" style="display:none; cursor: default"> 

<form name="userForm" id="userForm" method="post" action="" >
    <input type="text" class="required" id="email" name="email" maxlength="50" />
    <input type="text" class="firstname" id="firstname" name="firstname" />
    <input type="button" id="save" name="save" />

 </form> </div>

//和css

div#user {width:500px; height:400px;  background-image: url(/img/user.gif); background-repeat: no-repeat;}
input#email {position: absolute; left: 30px; width:200px; top:214px; height:20px;  background-color:#fff; border:0;}
input#firstname {position: absolute; left: 30px; width:200px; top:250px; height:20px; background-color:#fff; border:0;}

感谢您的宝贵时间 贾斯汀

【问题讨论】:

    标签: jquery position message validation


    【解决方案1】:

    您可以使用回调errorPlacement() 更改错误出现的位置。

    $("#myform").validate({
      errorPlacement: function(error, element) {
         error.appendTo( element.parent("td").next("td") );
       },
       debug:true
     })
    

    Source.

    【讨论】:

    • 所以我想,我将不得不更改为表格。我会让你知道它是如何工作的。谢谢
    • @Justin 不,你不需要,这只是一个例子。
    • 我最终使用了表格。我的问题是我有绝对对齐,并且通过使用表格来设置我需要放置元素的高度和长度,我能够在输入的右侧显示错误消息。再次感谢贾斯汀
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    相关资源
    最近更新 更多