This question already has answers here:
Get selected value of a dropdown's item using jQuery
                                
                                    (30个答案)
                                
                        
                                5年前关闭。
            
                    
我有这个<select>

 <select id="week" multiple="multiple" >
    <option value="1">Monday</option>
    <option value="2">Tuesday</option>
    <option value="3">Wednesday</option>
    <option value="4">Thursday</option>
    <option value="5">Friday</option>
    <option value="6">Saturday</option>
    <option value="7">Sunday</option>
</select>


我怎么知道在jQuery或JS中是否选择了每个<option>

最佳答案

您需要使用.is:

 $('#week option').each(function() {
        if($(this).is(':selected')){
      //code
   }
 });

关于javascript - 如何确定在多个<select>中选择了哪些选项? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25009212/

10-09 19:23