我不知道你的團隊日程是如何保存的,所以我做的東西了。基本上,當您選擇一個團隊時,會引用一個數組來查看該團隊可以使用哪些日子,然後禁用該菜單中相應的選項。
HTML:
<p>Choose a team:</p>
<div>
<input type="radio" name="team" id="team-a" value="0" />
<label for="team-a">Total Ballers</label>
</div>
<div>
<input type="radio" name="team" id="team-b" value="1" />
<label for="team-b">Party People</label>
</div>
<div>
<input type="radio" name="team" id="team-c" value="2" />
<label for="team-c">Weekend Warriors</label>
</div>
<p>Choose a day:</p>
<select>
<option>-- Choose a day --</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thurday</option>
<option>Friday</option>
<option>Saturday</option>
<option>Sunday</option>
</select>
JS(jQuery的):
//schedules are saved in a 2D array, the seven numbers correspond to Monday through Sunday
//1 = available, 0 = not available
//first set for team A, second for team B, third for team C
var schedules = [[1,1,1,1,1,1,1], [1,1,1,1,1,0,0], [0,0,0,0,0,1,1]];
$('input').on('click', function() {
//looks at the value of the clicked radio button
var value = $(this).val();
//grabs the corresponding array from schedules
var schedule = schedules[value];
//loops through each day in the menu, disable that option if the array shows a 0 for that day
$('option:not(:first-child)').each(function(i) {
if (!schedule[i]) {
$(this).attr('disabled', true).css('background-color','#eee');
} else {
$(this).attr('disabled', false).css('background-color','white');
}
});
}).on('change', function() {
$('option:first-child').attr('selected', true);
});
//last part changes the menu back to 'choose a day' when a different team is chosen
這裏有一個fiddle。
是的,你可以禁用一個特定的選項。閱讀[我如何啓用/禁用選擇框中使用jquery](http://stackoverflow.com/questions/10953589/how-do-i-enable-disable-options-in-select-box-using-jquery)可能會幫助你。沒有看到你的代碼,我們無法幫助你。 – Satpal 2014-09-11 07:13:50
爲什麼禁用?只是不顯示在選擇菜單中的選項..您可以使用onclick函數..張貼您的代碼,直到現在.. – ss56 2014-09-11 07:14:07
沒有人會給你一個完整的解決方案,沒有你顯示一些努力。自己嘗試一下,展示你做了什麼以及你在哪裏遇到了問題。 – Chris 2014-09-11 07:17:36