我正在使用jQuery验证插件,当我添加文本框所需的类时,它验证字段.但是,错误消息显示在文本框后面,我想知道我是否可以在相关文本框的标签后显示它?
我在iframe中有一个页面,当显示两个或多个错误消息时,表单变得太大而无法放入iframe.
我的标签和文本框:
<asp:Label ID="lblName" runat="server" Text="Your Name" /> <asp:TextBox ID="txtName" CssClass="required" runat="server"/> <br /> <asp:Label ID="lblEmail" runat="server" Text="Your Email"/> <asp:TextBox ID="txtEmail" CssClass="required email" runat="server"/> <br /> <asp:Label ID="lblNumber" runat="server" Text="Your Number"/> <asp:TextBox ID="txtNumber" CssClass="required" runat="server"/> <br /> <asp:Label ID="lblSubject" runat="server" Text="Subject"/> <asp:TextBox ID="txtSubject" CssClass="required" runat="server"/> <br /> <asp:Label ID="lblDetails" runat="server" Text="Details"/> <asp:TextBox ID="txtDetails" CssClass="required" TextMode="MultiLine" runat="server"/> <br /> <asp:Button ID="btnSubmit" CssClass="SubmitButton" runat="server" Text="" onclick="btnSubmit_Click" /> <asp:Label ID="lblResponse" CssClass="Response" runat="server" Text=""></asp:Label>
提前致谢.
解决方法
使用errorPlacement.例:
$("#field-GeoLatlon").validate({ rules: { "parameters[postcode]": { isPostcode: true },"parameters[houseno]": { startsWithNumber: true } },errorPlacement: errorPlacement }); function errorPlacement(error,element) { var errorDD = $('<dd class="error"></dd>').insertAfter(element.parent('dd').next('dd')); error.appendTo(errorDD); }