我有两个非常紧密的元素(下拉菜单).这些元素是必填字段.
我正在使用jquery valiate来验证字段.当元素附近显示第一个控件的错误消息时,两个元素之间的错误消息将显示,并且元素之间的空间增加
$('#RegisterForm').validate({ rules: { Country:{required: true},State:{required: true} },messages: { Country:{required: "Select Country"},State:{required: "Select State"} } });@H_403_5@我试过在元素之前使用break作为:
$('#RegisterForm').validate({ rules: { Country:{required: true},State:{required: true} },messages: { Country:{required: "<br/>Select Country"},State:{required: "<br/>Select State"} } });@H_403_5@当我这样做,第二个元素移动到下一行.
解决方法
使用errorPlacement选项(参见文档:
http://docs.jquery.com/Plugins/Validation/validate#toptions)
$('#RegisterForm').validate({ rules: { Country:{required: true},State:{required: "Select State"} },errorPlacement: function(error,element) { error.appendTo( element.parent("td").next("td") ); } });@H_403_5@当然,你必须根据你的情况调整代码.