errorPlacement的位置问题

时间:2023-03-08 18:35:39
errorPlacement的位置问题

做一个前端的验证,使用了JQUERY.Validate 在errorPlacement上纠结了半天:
百度大多数都是一个答案:
errorPlacement: function(error, element) {
if ( element.is(":radio") )
error.appendTo( element.parent().next().next() );
else if ( element.is(":checkbox") )
error.appendTo ( element.next() );
else
error.appendTo( element.parent().next() );
},
都是这种类型的
-----------------------------------------------------------------------------------------------------------------------------
而我出现的情况是 error信息总是出现在input的前面,调了很多次都没有弄好,最后浏览器F12发现 input的float是靠右的而导致这个问题
所以我之前想的是改变它的css
-----------------------------------------------------------------------------------------------------------------------------
最后在*上找到了我需要的答案:http://*.com/questions/2969381/jquery-validation-plug-in-custom-error-placement#comment3725397_3533250
也更改了一点地方,每个errorplacement都有固定的id,然后在其中生成
var errorPosition = $('#blocks-' + element.attr('id'));
error.appendTo(errorPosition); 对于我的情况能够行得通
API: http://www.runoob.com/jquery/jquery-plugin-validate.html