0

我正在准备体育设施的预订系统。在预订页面中,我创建了一个日历,并且出现了一些复杂情况。例如,如果用户选择星期六,我希望只显示一定数量的选项。我该怎么做?到目前为止,这是我的代码

<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" />&nbsp; Day:&nbsp;<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>
4

1 回答 1

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();
    }
}

是小提琴

于 2013-11-03T10:43:02.743 回答