gpt4 book ai didi

jquery 验证不会因复选框而被触发

转载 作者:行者123 更新时间:2023-12-01 06:16:50 25 4
gpt4 key购买 nike

我有一个表单,我使用 jQuery 验证从前端进行验证。

大部分验证都按照我想要的方式进行。但是,对于复选框,验证不起作用。我的验证 jquery 中有以下规则和消息

  $('#submitDetails').validate({
// 1. validation rules.
rules: {
......
......
......
custom9: {
required: true
},
custom10:{
required:true
},
custom11: {
required: true
}
},
// 2. Validation fail messages
messages: {
custom9: {
required: "You can only claim your Plush Rewards once you have received all your items found on your reciept"
},
custom10: {
required: "You must agree to the terms of conditions in order to claim your Plush Rewards Prepaid Visa Gift Card"
},
custom11: {
required: "You must agree to the terms of conditions in order to claim your Plush Rewards Prepaid Visa Gift Card"
}
......
......
......

html 是

<div class="ticks">
<div class="col-xs-12 tick1">
<input type="checkbox" data-label="Have you received your entire order from Plush?" name="custom9" id="custom9" value="0" class="styled myClass prettyCheckable"><span class="mandatory tick1Mandatory"> * </span>

</div>
<!--<div id="error_msg"></div> -->
<div class="col-xs-12 tick2">
<input type="checkbox" data-label="Please tick if you would like to join our mailing list and receive special bonus offers and the latest Plush news" name="custom10" id="custom10" value="1" class="styled myClass prettyCheckable" checked>
</div>
<div class="col-xs-12 tick3">
<input type="checkbox" data-label="I have read and agree to the Terms and Conditions of this promotion and understand the Plush Privacy Policy" name="custom11" id="custom11" value="0" class="styled myClass prettyCheckable"><span class="mandatory tick2Mandatory"> * </span>

</div>
</div>

当单击提交按钮时,与 custom9-11 相关的验证不会被触发。

最佳答案

这可能晚了几年,但以防万一其他人遇到这个问题:

从标记中我可以看出您正在为复选框使用 PrettyCheckable 插件。有可能您的实际复选框被 PrettyCheckable 隐藏并且验证插件忽略它们吗?

如果是这种情况,您可以尝试通过更改 jquery.validate 插件的忽略设置来修复此问题:

    $.validator.setDefaults({ 
ignore: [] // DON'T IGNORE PLUGIN HIDDEN SELECTS, CHECKBOXES AND RADIOS!!!
});

关于jquery 验证不会因复选框而被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18928092/

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