长期使用浏览器,第一次发帖。
我想做的是让用户在下拉菜单中选择要显示的周数,然后显示相应数量的div。目前我已经设置成可以显示一个div或全部,但我想对以前的div这样做。
目前我的代码如下:
<SELECT name="number_of_weeks" id="number_of_weeks">
<OPTION value = "week1">1</OPTION>
<OPTION value = "week2">2</OPTION>
<OPTION value = "week3">3</OPTION>
</SELECT>
<div id = "week1" class = "weekmenu">
Week 1 </br>
</div>
<div id = "week2" class = "weekmenu">
Week 2 </br>
</div>
<div id = "week3" class = "weekmenu">
Week 3 </br>
</div>
对于JavaScript而言:
$(document).ready(function () {
$('.weekmenu').hide();
$('#week1').show();
$('#number_of_weeks').change(function () {
$('.weekmenu').hide();
$('#'+$(this).val()).show();
});
});
输出应该类似于:如果选择了week1,只显示week1 div。如果选择了week2,则同时显示week1和week2 div。如果选择了week3,则显示week1、week2和week3 div。
我已经在努力解决这个问题了......我尝试创建一些嵌套的div,但效果不是很好。我还尝试给多个div分别设置它们自己的类,然后试图展示那些类。
JSFiddle:http://jsfiddle.net/meRcr/21/
非常感谢您的帮助!