简单描述:页面上方需要显示一个系统时间,会变化的!!!
代码:
//html代码
<li>
<p class="year" id="showYear" style="margin-right:10px!important;"></p>
<p class="day" id="showDay" style="margin-right:10px!important;"></p>
<p class="hours" id="showHour"></p>
</li>
<li>
<p class="year" id="showYear" style="margin-right:10px!important;"></p>
<p class="day" id="showDay" style="margin-right:10px!important;"></p>
<p class="hours" id="showHour"></p>
</li>
//js代码 //实现日期显示
/*<![CDATA[*/
$(function () {
window.setInterval(function () {
var today = new Date();
var week=new Array("星期一","星期二","星期三","星期四","星期五","星期六","星期日");
var now_day = week[today.getDay()-1];
var year = today.getFullYear();
var month = today.getMonth() + 1;
var date = today.getDate();
var hour = today.getHours();
var minute = today.getMinutes();
if (month < 10) month = "0" + month;
if (date < 10) date = "0" + date;
if (hour < 10) hour = "0" + hour;
if (minute < 10) minute = "0" + minute;
var showYearHmel = year + "年" + month + "月" + date + "日 ";
var showDayHtml = now_day;
var showHourHtml = hour + ":" + minute ;
$("#showYear").html(showYearHmel);
$("#showDay").html(showDayHtml);
$("#showHour").html(showHourHtml);
}, 1000);
})
/*]]>*/
说明一下:!important是是CSS1就定义的语法,作用是提高指定样式规则的应用优先权(参见:W3.org的解释)。语法格式{ sRule!important },即写在定义的最后面,例如:box{color:red !important;}
总结:网上有很多实时显示系统时间的,大同小异,但是用起来的话,还是拿自己的比较方便(其实也是别人的改过来的--!--)。