我正在尝试编写一个脚本,该脚本将生成 jQuery UI 将接受以制作手风琴的标记,如下所示。
<div id="accordion">
<h3>2012</h3>
<div>
<ul>
<li><a href="somepage.html?year=2012&month=10">October</a></li>
<li><a href="somepage.html?year=2012&month=9">September</a></li>
<li><a href="somepage.html?year=2012&month=8">August</a></li>
<li><a href="somepage.html?year=2012&month=7">July</a></li>
<li><a href="somepage.html?year=2012&month=6">June</a></li>
<li><a href="somepage.html?year=2012&month=5">May</a></li>
<li><a href="somepage.html?year=2012&month=4">April</a></li>
<li><a href="somepage.html?year=2012&month=3">March</a></li>
<li><a href="somepage.html?year=2012&month=2">February</a></li>
<li><a href="somepage.html?year=2012&month=1">January</a></li>
</ul>
</div>
<h3>2011</h3>
<div>
<ul>
<li><a href="somepage.html?year=2011&month=12>December</a></li>
<li><a href="somepage.html?year=2011&month=11>November</a></li>
<li><a href="somepage.html?year=2011&month=10">October</a></li>
<li><a href="somepage.html?year=2011&month=9">September</a></li>
<li><a href="somepage.html?year=2011&month=8">August</a></li>
<li><a href="somepage.html?year=2011&month=7">July</a></li>
<li><a href="somepage.html?year=2011&month=6">June</a></li>
<li><a href="somepage.html?year=2011&month=5">May</a></li>
<li><a href="somepage.html?year=2011&month=4">April</a></li>
<li><a href="somepage.html?year=2011&month=3">March</a></li>
<li><a href="somepage.html?year=2011&month=2">February</a></li>
<li><a href="somepage.html?year=2011&month=1">January</a></li>
</ul>
</div>
</div>
它应该输出年份以及当前和过去的几个月,一直到 2007 年。为了创建这种类型的标记,我需要做什么?伪代码:
var d = new Date();
var yr = Number(d.getFullYear());
for (var i = 2006, i < yr, i++)
{
//create a H3, div, and a ul
var mo = d.getMonth();
//some other for loop on the month to create the li items
//how to handle date display names?
}
jQuery/Javascript 中的日期一直是我的致命弱点。