我有多个选择要单击的选项。
例如。如果我单击第一个选项,则显示第一个选项indexvalue
HTML代码

<select class="founder_designation" rel="Designation" placeholder="Designation" multiple="multiple" name="designation">
<option value="">-- Select Designation --</option>
<option value="chairman_managing_director">Chairman &amp; Managing Director</option>
<option selected="selected" value="director" >Director</option>
<option value="whole_time_director">Whole Time Director</option>
<option value="other">Other</option>
</select>

jQuery代码
$(".founder_designation").on("change",function(){
  alert($(this).val());   //It display all selected options with comma separated
})

JS Fiddle

最佳答案

这将解决问题,

$('.founder_designation').on('click','option',function(){
 alert($(this).val());
});


如果您想要所有的价值,那么尝试这样的事情,

$('.founder_designation').on('click','option',function(){

    alert("clicked value:"+$(this).val());

    $a=$('.founder_designation option:selected');
    $str='';
    for($i=0;$i<$a.length;$i++){
        $str+=$('.founder_designation option:selected:eq('+$i+')').val()+",";
    }

    alert("all selected :"+$str);
});


检查演示
JS FIDDLE DEMO

关于javascript - 从多个选择中获取索引或单击选项的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26606456/

10-12 12:21