How to get number of selected options using jquery?

后端 未结 4 450
谎友^
谎友^ 2020-12-13 12:19

I have a multiple selection list which have more than 5 options. But i want to restrict the selection of the options to 2 or 3 options. How to do it using jquery? How to get

相关标签:
4条回答
  • 2020-12-13 12:47

    You can use the :selected selector to select them, then get the .length, like this:

    var count = $("#mySelect :selected").length;
    
    0 讨论(0)
  • 2020-12-13 12:48

    For checkboxes I'm using:

    $('input[name="InputName"]:checked').size()
    
    0 讨论(0)
  • 2020-12-13 12:49

    var n = $("input:checked").length; see this for more detail: http://api.jquery.com/checked-selector/

    0 讨论(0)
  • 2020-12-13 12:58

    You can get the number of selected items in the multiselect with the following:

    $('#selectList :selected').length
    

    Where #selectList is the id of your .

    0 讨论(0)
提交回复
热议问题