jQuery验证-至少选择20个字段中的3个 [英] jQuery Validation - Select at least 3 fields of 20

查看:83
本文介绍了jQuery验证-至少选择20个字段中的3个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我现在搜索了几个小时以寻求解决方案.我有20个字段(下拉列表),答案为是"和否".现在,我要验证用户必须对20个是"中的3个说出来.这是20个中的哪个都没关系.

Hi now I search several hours for a solution. I have 20 fields (dropdowns) with the answers "yes" and "no". Now I want to validate, that the user must say to 3 of the 20 "yes". Which this are from the 20 does not matter.

例如20个下拉菜单之一...

For example one of the 20 dropdowns...

<select name="dd1" id="dd1">
<option value="yes">Yes</option>
<option value="no" selected="selected">No</option>
</select>

有人有解决方案的想法吗?

Does anyone have an idea for a solution?

例如,对于验证,我使用以下格式:

For Validation I use for example this format:

 $(document).ready(function(){

    $("#register").validate({

        rules: {

            surname: {
                required: true,
                minlength: 3
            },

            messages: {
            surname: {
                required: "xxx",
                minlength: "xxx"
            },
            errorPlacement: function (error, element) {
             if ( element.is(":checkbox") )
             error.appendTo(element.parent("td").next("td"));
             else if ( element.is(":radio") )
             error.appendTo(element.parent("td").next("td"));
             else
             error.appendTo( element.parent());
            }

    });

  });

推荐答案

if ( $('select.my20drops[value="yes"]').length > 3 ) {
    // do something!
}

这篇关于jQuery验证-至少选择20个字段中的3个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆