JQuery错误验证的位置

时间:2010-12-04 06:08:17

标签: jquery css

我知道我们可以使用errorPlacement来设置错误消息的位置。我创建了一个有助于此的CSS。这是代码:

label.error {
    display: inline;
    clear: both;
    color:#200;
    margin:5px 0;
}

我必须做什么才能使用错误标签显示<input>旁边的错误   我创造了

1 个答案:

答案 0 :(得分:1)

在此处查看errorPlacement:选项:http://docs.jquery.com/Plugins/Validation/validate

    errorPlacement: function(error, element) {

     if (element.attr("name") == "someName"){
       error.insertBefore("input[name=someName]:first");
     }
     else{
       error.insertAfter(element);
     }
    },  

上面链接的api的另一个例子

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

修改

在示例中,它们只是样式化内联显示的.warning标签。

    #stepForm label.warning {
        text-align: left;
        width: auto;
        padding: 0;
        margin: 0 0 0 10px;
        float: none;
        clear: none;
        display: inline;
        color: #CC3366;
        font-size: 10px;
        border: none;
        border-top: 1px dotted #CC3366;
    }