下拉框时间显示

本文介绍了一个使用JavaScript编写的简单日期选择器脚本。该脚本能根据当前月份自动生成包含相应天数的下拉菜单,包括闰年判断。适用于网页表单中收集用户输入的日期。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      

脚本说明:   把如下代码加入<body>区域中

 <FORM>

<SELECT NAME="dates" SIZE=1>

<SCRIPT LANGUAGE="JavaScript">

//--------------------------------------------

//By mattias.sjoberg@swipnet.se 26/7-97

// The JavaScript Planet

// http://www.geocities.com/SiliconValley/7116

// You're welcome to use/edit this script, // just keep the comments and drop me a note.

//--------------------------------------------

        today = new Date();   

      thismonth = today.getMonth() + 1;    

     thisyear = today.getYear();        

thisday = today.getDate();

        maxdays=31;//default

        // months with 30 days      

   if (thismonth==4 || thismonth==6 || thismonth==9 || thismonth==11)  

       {              

   maxdays=30   

      }

        // february, leap year     

    if (thismonth==2)    

     {               

  // feb             

    if ((thisyear/4)!=parseInt(thisyear/4))      

           {                  

       maxdays=28     

            }             

    else            

     {             

            //leap year       

                  maxdays=29       

          }        

}

        thismonth = "" + thismonth

        if (thismonth.length == 1)    

     {              

   thismonth = "0" + thismonth;    

     }

        for (var theday = 0; theday <= maxdays; theday++)  

       {             

    if (theday == 0)          

       {                 

        document.write ("<OPTION SELECTED> "+ thisday + "-" + thismonth + "-" + thisyear )              

           document.write ("<OPTION> ========")        

         }

    

 

      else        

         {          

               var thed = "" + theday          

               if (thed.length == 1)        

                 {               

                  thed = "0" + thed;            

             }                    

     document.write ("<OPTION> " + thed + "-" + thismonth + "-" + thisyear)       

          }     

    }

</SCRIPT> </SELECT> </FORM>

 

 

 

转载于:https://www.cnblogs.com/fzm99/p/3330428.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值