当前位置: 代码迷 >> Web前端 >> 根据实际天数生成时间上拉列表
  详细解决方案

根据实际天数生成时间上拉列表

热度:154   发布时间:2012-11-22 00:16:41.0
根据实际天数生成时间下拉列表
//初始化下拉列表
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;
   }

?

?

  相关解决方案