How to get number of selected options using jquery?

后端 未结 4 473
谎友^
谎友^ 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;
    

提交回复
热议问题