//初始化下拉列表 function initSelectTime(dateNum,sysTime){ var rideDate = document.getElementById("rideDate"); $("currentTime").innerText=sysTime; //今天 var todayStr = sysTime.substring(0,10); var today = new Date(todayStr.replace(/-/g,"\/")); var tempOption = document.createElement("option"); rideDate.options.add(tempOption); tempOption.text = "今天 "+today.getFullYear()+"-"+checkTime(today.getMonth()+1)+"-"+checkTime(today.getDate())+" "+getDayOfWeek(today.getFullYear()+"-"+(today.getMonth()+1)+"-"+today.getDate()); tempOption.value = today.getFullYear()+"-"+checkTime(today.getMonth()+1)+"-"+checkTime(today.getDate()); tempOption.selected = "selected"; if(dateNum>2){ for(var i=2;i<=dateNum;i++){ var t = today.getTime() + 24*3600*1000*(i-1); var temDate = new Date(t); var tempOption = document.createElement("option"); rideDate.options.add(tempOption); var optionText = temDate.getFullYear()+"-"+checkTime(temDate.getMonth()+1)+"-"+checkTime(temDate.getDate())+" "+getDayOfWeek(temDate.getFullYear()+"-"+(temDate.getMonth()+1)+"-"+temDate.getDate()); if(i==2){ tempOption.text = "明天 "+optionText; }else if(i==3){ tempOption.text = "后天 "+optionText; }else{ tempOption.text = " "+optionText; } tempOption.value = temDate.getFullYear()+"-"+checkTime(temDate.getMonth()+1)+"-"+checkTime(temDate.getDate()); } } } //根据日期得到星期 function getDayOfWeek(dayValue){ //var dayValue = obj.value; var day = new Date(Date.parse(dayValue.replace(/-/g, '/'))); //将日期值格式化 var today = new Array("周日","周一","周二","周三","周四","周五","周六"); var week = today[day.getDay()]; //day.getDay();根据Date返一个星期中的某其中0为星期日 return week; }
?
?