首頁 > web前端 > js教程 > 主體

JS時間特效最常用的三款_javascript技巧

WBOY
發布: 2016-05-16 15:44:15
原創
1270 人瀏覽過

為大家分享的JS時間特效程式碼如下

<head>

<title>3个最常用的JS时间特效</title>
</head>

<body>
<table width="298" border="0" cellspacing="0" cellpadding="0">
 <tr>
 <td height="50" bgcolor="#f4f4f4">
<script language=JavaScript>
<!--
var enabled = 0; today = new Date();
var day; var date;
if(today.getDay()==0) day = " 星期日"
if(today.getDay()==1) day = " 星期一"
if(today.getDay()==2) day = " 星期二"
if(today.getDay()==3) day = " 星期三"
if(today.getDay()==4) day = " 星期四"
if(today.getDay()==5) day = " 星期五"
if(today.getDay()==6) day = " 星期六"
document.fgColor = "000000";
date = "今天是:" + (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日" + day +"";
document.write(date);
// -->
</script>
</td>
 </tr>
 <tr>
 <td height="50">
 <div id="webjx"></div>
 <script>setInterval("webjx.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
 </script></td>
 </tr>
 <tr>
 <td height="50" bgcolor="#f4f4f4">
 <span id=nowDate></span>
 <span id=nowTime></span>
 <script><!--
var ns4up1 = (document.layers) &#63; 1 : 0; // browser sniffer

var ie4up1 = (document.all&&(navigator.appVersion.indexOf("MSIE 4") == -1)) &#63; 1 : 0;

var ns6up1 = (document.getElementById&&!document.all) &#63; 1 : 0;

function nowclock() {
if (!ns4up1 && !ie4up1 && !ns6up1) return false;
var digital = new Date();
var hours = digital.getHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
var day = digital.getDate();
var month = digital.getMonth() + 1;
var year = digital.getYear();
var amOrPm = "AM";
if (hours > 11) amOrPm = "PM";
if (hours > 12) hours = hours - 12;
if (hours == 0) hours = 12;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
if (day < 10) day = "0" + day;
if (month < 10) month = "0" + month;
dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
dispDate = year + "年" + month + "月" + day+ "日, " ;
if (ns4up1) {
document.layers.nowTime.document.write(dispTime);
document.layers.nowTime.document.close();
document.layers.nowDate.document.write(dispDate);
document.layers.nowDate.document.close();
} else if (ns6up1){
document.getElementById("nowTime").innerHTML = dispTime;
document.getElementById("nowDate").innerHTML = dispDate;
} else if (ie4up1){
nowTime.innerHTML = dispTime;
nowDate.innerHTML = dispDate;
} setTimeout("nowclock()", 1000);
} nowclock();
//-->
 </script>

</td>
 </tr>
</table>

</body>
</html>
登入後複製

複製上面程式碼,直接運作即可得到下面的效果:

以上就是為大家分享的JavaScript時間特效程式碼,希望大家可以喜歡。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板