找了各种jquery时间插件,都必须带日期。

自己写个,根据实际使用环境改下就好

用于下拉框的

选择月份:<select name="apply_date" class="span2">

<option value="" class="date_div"></option>

     </select>

 

//className,生成的数据将要放到的class名称之后
function buildDate(className){
	//设置初始年份
	var start_year = 2010,dateStr='';
	DATE = new Date();
	now_year = DATE.getFullYear();
	for(var i=0; i<=(now_year-start_year); i++){
		dateStr = dateStr+buildMonth(start_year+i,'-');
	}
	//console.log(dateStr);
	$('.'+className).after(dateStr);

	//年,年月之间的分隔符
	function buildMonth(year,connector){
		var dateStr='';
		var monthObj = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
		for(var i=0; i<12; i++){
			dateStr = dateStr+'<option value="'+year+connector+monthObj[i]+'">'+year+connector+monthObj[i]+'</option>';
		}
		return dateStr;
	}
}

buildDate('date_div');

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

et_highlighter