javascript 中当前时间年份的前后5年在下拉框中显示出来 ,应该怎么写??

解决方案 »

  1.   

    由于是10年的所有日期,所以加载有点慢,我这里需要30秒
    <!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>
      

  2.   

    function getDate()
    {
    Date now=new Date().getYear();
    for(var i=now;i>now-5;i--)
    {
       Document.getElementById("下拉列表的ID").options.add(i,i);
    }}
      

  3.   

    select sysdate from dual 在oracle中可以得到当前时间,那么当前时间的前五年,就应该不有问题啦
      

  4.   

    我现在就要年份,不要别的月和日,要在前台用SCRIPT显示出来,当前时间的前后五年,只要JAVASCRIPT的
      

  5.   


    <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>