<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 147  文章 - 71  trackbacks - 0
    <2009年4月>
    2930311234
    567891011
    12131415161718
    19202122232425
    262728293012
    3456789

    常用鏈接

    留言簿(1)

    隨筆分類(146)

    隨筆檔案(147)

    文章分類(28)

    文章檔案(28)

    喜歡的Blog

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    Javascript實現日期星期全顯示,項目的需要顯示日期和星期,下面代碼就可以顯示當前的日期和星期
    <html>
    <body>
    <script language=javascript>
    <!--
    todayDate 
    = new Date();
    date 
    = todayDate.getDate();
    month
    = todayDate.getMonth() +1;
    year
    = todayDate.getYear();
    document.write(
    "今天是")
    document.write(
    "<br>")
    if(navigator.appName == "Netscape")
    {
        document.write(
    1900+year);
        document.write(
    "");
        document.write(month);
        document.write(
    "");
        document.write(date);
        document.write(
    "");
        document.write(
    "<br>")
    }

    if(navigator.appVersion.indexOf("MSIE"!= -1)
    {
    document.write(year);
    document.write(
    "");
    document.write(month);
    document.write(
    "");
    document.write(date);
    document.write(
    "");
    document.write(
    "<br>")
    }

    if (todayDate.getDay() == 5) document.write("星期五")
    if (todayDate.getDay() == 6) document.write("星期六")
    if (todayDate.getDay() == 0) document.write("星期日")
    if (todayDate.getDay() == 1) document.write("星期一")
    if (todayDate.getDay() == 2) document.write("星期二")
    if (todayDate.getDay() == 3) document.write("星期三")
    if (todayDate.getDay() == 4) document.write("星期四")

    //--> 
    </script>
     
    </body>
    </html>

        todayDate = new Date();

    當定義一個新的對象時,通常使用“new”操作符。在這里,就是創建了日期對象。

    date = todayDate.getDate(); getDate()是Date對象的一種方法,其功能是獲得當前的日期。
    month= todayDate.getMonth() + 1 ;

     getMonth()是Date對象的一種方法,其功能是獲得當前的日期,由于月份是從0開始的,所以這里要“+1”。

    year= todayDate.getYear() getYear()是Date對象的一種方法,其功能是獲得當前的年份。
    if(navigator.appName == "Netscape") { document.write(1900+year); document.write("年"); document.write(month); document.write("月"); document.write(date); document.write("日");
    document.write("<br> ") }
    如果瀏覽器是Netscape,輸出今天是“year”+“年”+“month”+“月”+“date”+“日”,其中年要加1900。
    if(navigator.appVersion.indexOf("MSIE") != -1) { document.write(year); document.write("年"); document.write(month); document.write("月"); document.write(date); document.write("日");
    document.write("<br> ") }
    如果瀏覽器是IE,直接輸出今天是“year”+“年”+“month”+“月”+“date”+“日”。
    if (todayDate.getDay() == 5) document.write("星期五");
    if (todayDate.getDay() == 6) document.write("星期六");
    if (todayDate.getDay() == 0) document.write("星期日");
    if (todayDate.getDay() == 1) document.write("星期一");
    if (todayDate.getDay() == 2) document.write("星期二");
    if (todayDate.getDay() == 3) document.write("星期三");
    if (todayDate.getDay() == 4) document.write("星期四")
    getDay()是Date對象的一種方法,其功能是獲得當前是星期幾。document.write輸出今天是“星期幾”。
    posted on 2009-04-06 10:45 飛翔天使 閱讀(2216) 評論(3)  編輯  收藏 所屬分類: javascript

    FeedBack:
    # re: javascript實現日期星期的顯示 2009-04-07 09:06 haix
    不錯,支持
    firefox那  回復  更多評論
      
    # re: javascript實現日期星期的顯示 2010-01-21 10:56 黑葉拜天
    新手!學習啦~
    謝謝呀  回復  更多評論
      
    # re: javascript實現日期星期的顯示 2014-05-27 15:18 ii
    if (todayDate.getDay() == 5) document.write("星期五");
    if (todayDate.getDay() == 6) document.write("星期六");
    if (todayDate.getDay() == 0) document.write("星期日");
    if (todayDate.getDay() == 1) document.write("星期一");
    if (todayDate.getDay() == 2) document.write("星期二");
    if (todayDate.getDay() == 3) document.write("星期三");
    if (todayDate.getDay() == 4) document.write("星期四")  回復  更多評論
      
    主站蜘蛛池模板: 国产成人麻豆亚洲综合无码精品| a级大片免费观看| 性色av无码免费一区二区三区| 亚洲av永久无码精品漫画 | 亚洲国产精品线观看不卡| 男女作爱在线播放免费网站| 国产偷国产偷亚洲高清日韩| xxxxx做受大片在线观看免费| 免费一级黄色毛片| 永久免费无码日韩视频| 久久亚洲中文字幕精品一区| 中文字幕成人免费高清在线| 久久精品国产亚洲av麻豆| 久久免费精彩视频| 亚洲欧洲国产精品久久| a毛片基地免费全部视频| 亚洲欧美精品午睡沙发| 成人永久免费高清| 美女裸免费观看网站| 免费一级一片一毛片| 一级一看免费完整版毛片| 亚洲福利中文字幕在线网址| 福利片免费一区二区三区| 亚洲AV无码一区二三区 | 午夜免费不卡毛片完整版| 亚洲午夜无码毛片av久久京东热| 日韩免费高清视频| 精品人妻系列无码人妻免费视频 | 亚洲∧v久久久无码精品| 精品久久久久成人码免费动漫| 亚洲精品V天堂中文字幕| 亚洲综合亚洲综合网成人| 日本免费A级毛一片| 一本天堂ⅴ无码亚洲道久久| 亚洲国产精品人人做人人爱| 暖暖免费日本在线中文| 亚洲风情亚Aⅴ在线发布| 亚洲最大AV网站在线观看| 亚洲一级毛片免费在线观看| 国产午夜亚洲精品不卡免下载| 亚洲av伊人久久综合密臀性色 |