如何限制选择字段中的不同选择?

时间:2019-07-07 10:24:02

标签: javascript jquery forms jquery-chosen

我有3个不同的多选字段,我想为这些字段设置不同的限制。如何为不同的类设置max_selected_options?

这是我页面上的js代码:

<script type="text/javascript">
    $('.form-control-chosen').chosen({
        max_selected_options: 5,
        allow_single_deselect: true,
        width: '100%'
    });
    $('.form-control-chosen-required').chosen({
        allow_single_deselect: false,
        width: '100%'
    });
    $('.form-control-chosen-search-threshold-100').chosen({
        allow_single_deselect: true,
        disable_search_threshold: 100,
        width: '100%'
    });

    $(function () {
        $('[title="clickable_optgroup"]').addClass('chosen-container-optgroup-clickable');
    });
    $(document).on('click', '[title="clickable_optgroup"] .group-result', function () {
        var unselected = $(this).nextUntil('.group-result').not('.result-selected');
        if (unselected.length) {
            unselected.trigger('mouseup');
        } else {
            $(this).nextUntil('.group-result').each(function () {
                $('a.search-choice-close[data-option-array-index="' + $(this).data('option-array-index') + '"]').trigger('click');
            });
        }
    });
</script>

1 个答案:

答案 0 :(得分:0)

您可以使用Id代替类作为选择器

Option Explicit

Sub Sample()
    Dim wbNames As Workbook, wbSep As Workbook
    Dim rng As Range, aCell As Range

    Set wbNames = Workbooks("names.xlsm")
    Set wbSep = Workbooks("separate.xlsx")

    Set rng = wbNames.Sheets("Names").Range("A2:A6")

    For Each aCell In rng
        With wbSep
            .Sheets.Add(After:=.Worksheets(.Worksheets.Count)).Name = aCell.Value
            .Worksheets(aCell.Value).Cells(1, 1).Value = aCell.Value
        End With
    Next
End Sub