jQuery验证自定义错误消息显示为单选按钮 [英] jQuery validation custom error message display for radio button
本文介绍了jQuery验证自定义错误消息显示为单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery验证并尝试获取一对单选按钮的错误消息,以在第一个按钮之前显示。
以下是验证:
errorPlacement:function(error,element){
if(element.attr(type)== radio)
error.insertBefore(element.first());
else
error.insertAfter(element);
$ / code>
这里是html:
< div class =full>
< label id =sample>您是否收到您的样品包?< / label>
< input type =radioname =sampleid =sample_yesvalue =yes/>
< label for =eliteflexsample_yes>是< / label>
< input type =radioname =sampleid =sample_novalue =no/>
< label for =eliteflexsample_no>否< / label>
< / div>
现在错误显示在第一个单选按钮之后。
$(document)。解决方案 ready(function(){
$ b $('form')。validate({
//您的验证选项,
errorPlacement:function(错误,元素){
if(element.attr(type)==radio){
error.insertBefore(element);
} else {
error。 insertAfter(element);
}
}
});
});
http:// jsfiddle。 net / DR5Aw / 2 /
I'm using jQuery validation and trying to get the error message for a pair of radio buttons to show up before the first button.
Here is the validation:
errorPlacement: function(error, element) {
if (element.attr("type") == "radio")
error.insertBefore(element.first());
else
error.insertAfter(element);
}
Here is the html:
<div class="full">
<label id="sample">Have you received your sample pack?</label>
<input type="radio" name="sample" id="sample_yes" value="yes" />
<label for="eliteflexsample_yes">Yes</label>
<input type="radio" name="sample" id="sample_no" value="no" />
<label for="eliteflexsample_no">No</label>
</div>
Right now the error is showing up after the first radio button.
解决方案
This is working:
$(document).ready(function() {
$('form').validate({
// your validation options,
errorPlacement: function(error, element) {
if (element.attr("type") == "radio") {
error.insertBefore(element);
} else {
error.insertAfter(element);
}
}
});
});
这篇关于jQuery验证自定义错误消息显示为单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文