我正在准备体育设施预订系统。在预订页面中,我创建了一个日历,我有一些复杂的问题。例如,如果用户选择星期六,我只想显示一定数量的选项。我该怎么做?到目前为止,这是我的代码
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker({
altField: "#alternate",
altFormat: "DD"
});
});`
</script>
<form action="booking.php" method="post">
<tr><td>Sports Facility:</td><td><select name = "sports_facility">
<option name="sport1" value = "Basketball">Basketball</option>
<option name="sport6" value = "Tennis">Tennis Court (Multistorey Carpark)</option></td></tr>
</select>
</table>
<tr><td>Date:</td><td><input type="text" id="datepicker" name="datePicker" /> Day: <input type="text" id="alternate" name="vAlternate" size="8" /></td></tr>
<tr><td>Time:</td><td><select>
<option value="Time 1">9.00am-11.00am</option>
<option value="Time 2">11.00am-1.00pm</option>
<option value="Time 3">1.00pm-3.00pm</option>
<option value="Time 7">9.00pm-11.00pm</option> </select>
</td></tr>
</table>
</form>
答案 0 :(得分:1)
您可以为“选择”和“选项”提供ID。像这样:
<select id="time">
<option id="option_1" value="Time 1">9.00am-11.00am</option>
<option id="option_2" value="Time 2">11.00am-1.00pm</option>
<option id="option_3" value="Time 3">1.00pm-3.00pm</option>
</select>
之后,您可以添加JS过滤器。
$(function(){
var filters = [];
filters['Sunday'] = [1,3];
filters['Monday'] = [1,2];
//Etc...
}
然后,当您想要应用这些过滤器时,您可以执行以下操作:
function displayOptionsByDay(day){
$('#time option').css('display', 'none').wrap('<span style="display: none;"/>');
for(var i = 0; i < filters[day].length; i++){
$('#option_' + filters[day][i]).css('display', 'inline').unwrap();
}
}
Here是小提琴