我有一個下拉選項和三個選項。最初啓用了三個選項。在選擇'收入頂線'或'保證金' - >'其他'選項時應該禁用。同樣在選擇「其他人」時應該禁用。 如果我取消已選定的選項仍然是「其他」選項處於禁用狀態only..how,使沒有選定......你能幫我如何在下拉菜單中沒有選擇任何選項時啓用這些選項
$("#outcomes").click(function() {
var name = outcomes.options[outcomes.selectedIndex].value;
if (name == 'others') {
//$('option[value=Margin]').prop('disabled', this.value === 'others');
$('option[value=Revenue-top-line]').prop('disabled', true);
$('option[value=Margin]').prop('disabled', true);
document.getElementById('div1').innerHTML = '<input type="text" id="others" name="others" autocomplete="off" />';
} else {
document.getElementById('div1').innerHTML = '';
$('option[value=Revenue-top-line]').prop('disabled', false);
$('option[value=Margin]').prop('disabled', false);
$('option[value=others]').prop('disabled', true);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td>
<select class="outcomes" id="outcomes" name="keyOutcomes" multiple="multiple" style="width: 310px;" onchange="">
<option value="Revenue-top-line">Revenue top-line</option>
<option value="Margin">Margin(CTS/Client)</option>
<option value="others">others</option>
</select> <span id="outcomeaddress" style="margin-top: 29px; margin-left: 275px; color: red;"></span>
<div id="div1"></div>
</td>
首先,您不應該在具有'multiple'屬性集的select中使用'selectedIndex'和'value' - 因爲那樣只會給您選擇_first_選項的索引/值。對於允許選擇多個選項的選擇,您需要遍歷選項並檢查每個選項是否被單獨選中。 – CBroe