jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用jQuery验证验证多个复选框大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图采取一些复选框,并确保使用jQuery验证至少检查其中一个复选框.到目前为止我没有运气.我错过了什么?我知道我的验证是因为它适用于其他领域,而不是我的复选框.我把代码放在 jfiddle上,也许这会有所帮助.

编辑:我为我的输入名称=列表参数(列表[])添加了括号.同样在我的规则中,我将名称参数从列表更改为’list []’.我的旧代码如下.谢谢Sparky!

OLD: <input type='checkBox' name='list' id='fullProduct'></input>

FIXED: <input type='checkBox' name='list[]' id='fullProduct'></input>

这是我的代码.

$("#TradeForm").validate({
        rules: {
            startDate: {
                required: true,date: true
            },endDate: {
                required: true,showName: {
                required: true,minlength: 5
            },LOCATIOn: {
                required: true
            },list: {
                required: true
            }
        },messages: {
            startDate: "*",endDate: "*"
    }
});

                <table>
                <tr>
                    <th>Name of Show</th>
                    <td> <input type='text' name='showName'></input></td>
                </tr>
                <tr>
                    <th>LOCATIOn</th>
                    <td><input type='text' name='LOCATIOn'></input></td>
                </tr>
                <tr>
                    <th><span style='padding-right: 50px;'>SELEct Literature</span></th>
                    <td><input type='checkBox' name='list' id='fullProduct'></input><span style='font-size: 12px;'>Guide One</span></td>
                    <td><input type='checkBox' name='list' id='oilProduct'></input><span style='font-size: 12px;'>Guide Two</span></td>
                </tr>                               
                <tr>                                
                    <td></td>                       
                    <td><input type='checkBox' name='list' id='diamondProduct'></input><span style='font-size: 12px;'>Guide Three</span></td>
                    <td><input type='checkBox' name='list' id='motorProduct'></input><span style='font-size: 12px;'>Guide Four</span></td>
                </tr>                               
            </table>

解决方法

复选框组的名称是list [],而不是list,因此您必须声明规则. Since it contains brackets,[],you must enclose it in quotes

rules: {
    'list[]': {
        required: true
    }
},

你的jsfiddlehttp://jsfiddle.net/ZDz59/1/

@H_419_35@

大佬总结

以上是大佬教程为你收集整理的使用jQuery验证验证多个复选框全部内容,希望文章能够帮你解决使用jQuery验证验证多个复选框所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。