时间 <br>$(function(){ <br> initDate(); <br>}); <br>//格式化日期函数 <br><br>function formateDate(date){ <br>if(date instanceof Date){ <br>var time=date.getMonth()+1; <br>var day=date.getDate(); <br> if(day==31){ <br> var myDate = new Date(date.getFullYear(),date.getMonth(), 0); <br> date.setDate(myDate.getDate()); <br> time=time-1; <br> if(time==0){ <br> time=time+1; <br> <br> } <br><br><br><br>} <br>if(time<10){ <br/>time="0"+time; <br/>} <br/>return date.getFullYear()+""+time; <br/>} else { <br/>return "Error Date"; <br/>} <br/>} <br/><br/>//页面加载完成后,执行初始化操作 <br/>function initDate(){ <br/>//当前日期 <br/>var date = new Date(); <br/>//获取select元素 <br/>$("#dateSelect").empty().append("<option value=''></option>"); <br>for (var i = 0; i < 6; i++) { <br/>$("#dateSelect").append( <br/>"<option value='" + formateDate(date) + "'>" <br>+ formateDate(date) + "</option>"); <br>//日期减一个月 <br>date.setMonth(date.getMonth() - 1); <br>} <br>}; <br><br>