gpt4 book ai didi

forms - 单选按钮的 jQuery 验证自定义错误消息显示

转载 作者:行者123 更新时间:2023-12-01 09:07:33 26 4
gpt4 key购买 nike

我正在使用 jQuery 验证并尝试获取一对单选按钮的错误消息以显示在第一个按钮之前。

这是验证:

errorPlacement: function(error, element) {
if (element.attr("type") == "radio")
error.insertBefore(element.first());
else
error.insertAfter(element);
}

这是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>

现在错误出现在第一个单选按钮之后。

最佳答案

这是有效的:

$(document).ready(function() {

$('form').validate({

// your validation options,

errorPlacement: function(error, element) {
if (element.attr("type") == "radio") {
error.insertBefore(element);
} else {
error.insertAfter(element);
}
}

});

});​

Working Demo:

http://jsfiddle.net/DR5Aw/2/

关于forms - 单选按钮的 jQuery 验证自定义错误消息显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11123055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com