<html> <head> <title>无标题文档</title> <script> function showDate(){; var year = new Date().getYear() - 5; for(var i = 0; i< 11; i++){ select1.options[i] = new Option(year + i, year + i, false, false); } } </script> </head><body onload="showDate()"> <select id="select1"></select> </body> </html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<title></title>
<script>
Date.prototype.format = function(format)
{
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
(this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length==1 ? o[k] :
("00"+ o[k]).substr((""+ o[k]).length));
return format;
}function showDate(){
var beginDate = new Date(new Date().setYear(new Date().getYear() - 5));
var endDate = new Date(new Date().setYear(new Date().getYear() + 5)); var i = 0;
while(beginDate.getTime() <= endDate.getTime()){
select1.options[i] = new Option(beginDate.format("yyyy年MM月dd日"),"" + beginDate,false,false);
beginDate.setDate(beginDate.getDate() + 1);
i++;
}
}
</script>
</head><body onload="showDate()">
<select id="select1"></select>
</body>
</html>
{
Date now=new Date().getYear();
for(var i=now;i>now-5;i--)
{
Document.getElementById("下拉列表的ID").options.add(i,i);
}}
<html>
<head>
<title>无标题文档</title>
<script>
function showDate(){;
var year = new Date().getYear() - 5;
for(var i = 0; i< 11; i++){
select1.options[i] = new Option(year + i, year + i, false, false);
}
}
</script>
</head><body onload="showDate()">
<select id="select1"></select>
</body>
</html>