我正在使用 jquery validate插件来验证我的表单字段. 脚本如下所示 jQuery(document).ready(function($){ $.validator.addMethod( "mydate", function(value, element) { return value.match(/^\d\d?\-\d\d?\-\d\d\d\d$/); }, "Please
脚本如下所示
jQuery(document).ready(function($){ $.validator.addMethod( "mydate", function(value, element) { return value.match(/^\d\d?\-\d\d?\-\d\d\d\d$/); }, "Please enter a date in the format dd-mm-yyyy" ); var validator = $("#signupform").validate({ rules: { User: { required: true, remote: { url: "user.php", type: "post", }, }, "RID[]": { required: true, remote: { url: "resource.php", type: "post", }, }, Date: { required: true, mydate : true }, }, messages: { User: "Specify Active User", "RID[]": "Specify Available Resource", Date: "Specify Date" }, errorPlacement: function(error, element) { error.appendTo( element.parent().next() ); }, success: function(label) { label.html("OK").addClass("checked"); } });
它验证了我的一个表单字段
<tr> <td style="width: 70px" class="style22" valign="top">Resource ID</td> <td id="resource" style="width: 267px;"> <input id="resource" name="RID[]" type="text" value="" style="width: 232px" /></td> <td class="style21" style="width: 160px" valign="top"> <img id="addScnt" alt="[+]" src="+.gif"/> </td> <td> </td> </tr>
但我想在特定的div< div id =“errorcontainer2”>中为“RID []”设置错误.
我怎么能这样做?
提前致谢.. :)
blasteralfred
我使用特定div中的自定义错误放置解决了它< div id =“errorbox”>errorPlacement: function(error, element){ if(element.attr("name") == "RID[]"){ error.appendTo($('#errorbox')); }else{ error.appendTo( element.parent().next() ); } }