我不知道你的团队日程是如何保存的,所以我做的东西了。基本上,当您选择一个团队时,会引用一个数组来查看该团队可以使用哪些日子,然后禁用该菜单中相应的选项。
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