Get value of multiselect box using jQuery or pure JS

前端 未结 6 1270
傲寒
傲寒 2020-12-03 02:11

In the code shown below, how to get the values of multiselect box in function val() using jQuery or pure JavaScript?



        
6条回答
  •  被撕碎了的回忆
    2020-12-03 03:05

    I think the answer may be easier to understand like this:

    $('#empid').on('change',function() {
      alert($(this).val());
      console.log($(this).val());
    });
    
    
    
    Hold CTRL / CMD for selecting multiple fields

    If you select "Carrot" and "Raisins" in the list, the output will be "1,3".

提交回复
热议问题