jQuery验证特定位置的错误放置 [英] jquery validate errorplacement with a specific place

查看:53
本文介绍了jQuery验证特定位置的错误放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用jquery validate验证我的表单,但我想将我的错误标签放到特定的地方.下面的示例显示在<span class="error_label"></span>中放置的错误标签.我的问题是如何在特定位置进行错误放置,下面是一个示例,请帮助我..谢谢?

i want to validate my form with jquery validate but i want to put my error label to a specific place. an example below show error label put in the <span class="error_label"></span>. my question is how can i make errorplacement with a specific place, with an example below, please help me..thanks?

<script>
$(document).ready(function (){
$("#fm_regis").validate({
    rules :{
        name: {
            required: true,
        },
    },
    errorPlacement: function(error, element) {      
        //$(element).next('span .error_label :first').html(error);
        //$('.error_label').html(error);
        //$('.error_label').html(error);
        $(element).closest('.error_label').html(error);
    },
    messages: {
        name: {
            required: "Please input a username",
        },
    }
});
});
</script>

    <form name="fm_regis" id="fm_regis">
    <table>   
      <tr>
         <td width="100">Nama</td>
         <td>:</td>
         <td><input type="text" name="name" id="name" size="30"/></td>
      </tr> 
      <tr>
         <td width="100"></td>
         <td></td>
         <td><span class="error_label"></span></td>
      </tr>
   </table>
     <input type="submit" value="Register"/>
   </form>

推荐答案

在您的特定情况下,您可以执行以下操作:

In your specific situation you can do something like this:

$(element).closest('tr').next().find('.error_label').html(error);

http://jsfiddle.net/kqTQu/

这篇关于jQuery验证特定位置的错误放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆