我试图获取多个特定的类选择每个选定的值我无法实现它例如我有3个选择类Candidates_dd
并且我希望选择的特定类选择的值选择由逗号分隔{{ 1}}。
HTML
,
JS
<select class="Candidates_dd" id="Candidate_for_po_1">
<option value="1">None of the mentioned candidates</option>
<option value="AB4BB5">AB4BB5 - 1 1</option>
<option value="C3B239">C3B239 - 2 2</option>
<option value="E2A3D3">E2A3D3 - 33 3</option>
<option value="HFDG35">HFDG35 - 4 4</option>
</select>
<select class="Candidates_dd" id="Candidate_for_po_2">
<option value="2">None of the mentioned candidates</option>
<option value="AB4BB5">AB4BB5 - 1 1</option>
<option value="C3B239">C3B239 - 2 2</option>
<option value="E2A3D3">E2A3D3 - 33 3</option>
<option value="HFDG35">HFDG35 - 4 4</option>
</select>
<select class="Candidates_dd" id="Candidate_for_po_3">
<option value="3">None of the mentioned candidates</option>
<option value="AB4BB5">AB4BB5 - 1 1</option>
<option value="C3B239">C3B239 - 2 2</option>
<option value="E2A3D3">E2A3D3 - 33 3</option>
<option value="HFDG35">HFDG35 - 4 4</option>
</select>
答案 0 :(得分:0)
这很简单终于解决了问题
$(document).ready(function () {
var arr = [];
$('.Candidates_dd option:selected').each(function () {
arr.push($(this).val())
});
alert(arr.join(','));
})