本文介绍了利用Javascript在网页上计算当前月份的剩余天数的方法,大家参考使用吧!
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 |
<script language = “JavaScript” > var today = new Date ( ) ; var now = today. getDate ( ) ; var year = today. getYear ( ) ; if (year < 2000 ) year += 1900 ; // Y2K fix var month = today. getMonth ( ) ; var monarr = new Array ( 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ) ; // check for leap year if ( ( (year % 4 == 0 ) && (year % 100 != 0 ) ) || (year % 400 == 0 ) ) monarr [ 1 ] = “29” ; // display day left document. write ( “这个月还剩 “ + (monarr [month ] –now ) + ” 天了” ) ; </script > |
» JavaScript计算当月剩余天数(天数计算器)示例代码
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。