如果選擇了room2和room4,我試圖從選擇框中刪除最後2個選項。我無法讓它工作。有任何想法嗎? 同樣在第三個選擇框,如果選項更多被選中我想7天自動被選中並顯示警報:聯繫辦公室長期停留。如何從選擇框中刪除選項
$('#calculator_accomodation').change(function(){
if($(this).val() == 'ROOM2' || $(this).val() == 'ROOM4'){
$("#cost_calculator_person").option("5").remove();
$("#cost_calculator_person").option("6").remove();
alert('room2 is triggered')
}
});
$('#cost_calculator_days').change(function(){
if($(this).val() == 'More') {
alert('Contact office for long stay');
// code to select '7' goes here
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="calculator_accomodation" name="calculator_accomodation">
<option value="ROOM1">ROOM ONE</option>
<option value="ROOM2">ROOM TWO</option>
<option value="ROOM3">ROOM TREE</option>
<option value="ROOM4">ROOM FOUR</option>
<option value="ROOM5">ROOM FIVE</option>
<option value="ROOM6">ROOM SIX</option>
<option value="ROOM7">ROOM SEVEN</option>
<option value="ROOM8">ROOM EIGHT</option>
</select>
<select id="cost_calculator_person" name="cost_calculator_person">
<option value="1">1 PERSON</option>
<option value="2">2 PEOPLE</option>
<option value="3">3 PEOPLE</option>
<option value="4">4 PEOPLE</option>
<option value="5">5 PEOPLE</option>
<option value="6">6 PEOPLE</option>
</select>
<select name="cost_calculator_days" id="cost_calculator_days">
<option selected="" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="More">More</option>
</select>
使用這種@ Hijacker83 $(」 #cost_calculator_person選項[value ='5']「)。rem OVE(); – PRABA
@ hijacker83爲您的日期選擇答案已更新 –