我正在尝试显示当前月份的选项卡式窗格。使用 Bootstrap 的选项卡方法。想知道是否有人看到此代码中的任何缺陷?到目前为止,它正在按照我想要的方式工作,使用和测试自己。
的HTML
<ul class="nav nav-tabs" id="monthsTab">
<li><a href="#January" id="janLink" data-toggle="tab">January</a></li>
<li><a href="#February" id="febLink" data-toggle="tab" >February</a></li>
<li><a href="#March" id="marLink" data-toggle="tab">March</a></li>
<li><a href="#April" id="aprLink" data-toggle="tab">April</a></li>
<li><a href="#May" id="mayLink" data-toggle="tab">May</a></li>
<li><a href="#June" id="junLink" data-toggle="tab">June</a></li>
<li><a href="#July" id="julLink" data-toggle="tab">July</a></li>
<li><a href="#August" id="augLink" data-toggle="tab">August</a></li>
<li><a href="#September" id="sepLink" data-toggle="tab">September</a></li>
<li><a href="#October" id="octLink" data-toggle="tab">October</a></li>
<li><a href="#November" id="novLink" data-toggle="tab">November</a></li>
<li><a href="#December" id="decLink" data-toggle="tab">December</a></li>
</ul>
和 JS:
var currentMonth = function () {
var myMonth=new Date();
var theMonth = myMonth.getMonth();
var target = '';
var month = '';
switch (theMonth) {
case 0:
target = "janLink";
month = "January";
break;
case 1:
target = "febLink";
month = "February";
break;
case 2:
target = "marLink";
month = "March";
break;
case 3:
target = "aprLink";
month = "April";
break;
case 4:
target = "mayLink";
month = "May";
break;
case 5:
target = "junLink";
month = "June";
break;
case 6:
target = "julLink";
month = "July";
break;
case 7:
target = "augLink";
month = "August";
break;
case 8:
target = "sepLink";
month = "September";
break;
case 9:
target = "octLink";
month = "October";
break;
case 10:
target = "novLink";
month = "November";
break;
case 11:
target = "decLink";
month = "December";
break;
}
$('#monthsTab, ' + '#' + target).parent().addClass('active');
$('#'+month).addClass('active');
};
currentMonth();