当前位置:站长之家学习教程网站运营网站建设 → 文章内容

在下拉式的Form框中显示时间

减小字体 增大字体 作者:佚名  来源:不详  发布时间:2006-5-24 10:24:59

要完成此效果把如下代码加入到<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>

文章评论评论内容只代表网友观点,与本站立场无关!

  评论人:Lee   打分:85 分  发表时间:2007-5-5 19:49:18
· http://f8b7fb522d73dcf936a2e66e6ec38296-t.ghoiou0.info&lt;ahref...