最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript時間自動刷新實現(xiàn)原理與步驟

 更新時間:2013年01月06日 16:59:52   作者:  
javascript時間自動刷新在應(yīng)用中很常見,本人今天整理了一些,感興趣的朋友可以參考下哦

項目結(jié)構(gòu):

運行效果:

=========================================================

代碼部分:

=========================================================

/Clock/WebContent/index.jsp

復(fù)制代碼 代碼如下:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<span id="clock"> </span>
</body>
<script type="text/javascript" src="<%=basePath%>js/clock/clock.js" charset="UTF-8"></script>
</html>

/Clock/WebContent/js/clock/clock.js
復(fù)制代碼 代碼如下:

/**
* 時間顯示
* @date 2012-12-31
* @author hongten(hongtenzone@foxmail.com)
*
* @returns
*/
function Clock() {
var date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth() + 1;
this.date = date.getDate();
this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

// 日期:2012-12-31-17:03:18 星期一
this.toString = function() {
return "日期:" + this.year + "-" + this.month + "-" + this.date + "-" + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;
};

// 2012-12-31
this.toSimpleDate = function() {
return this.year + "-" + this.month + "-" + this.date;
};

// 2012-12-31 17:04:03
this.toDetailDate = function() {
return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
};

this.display = function(ele) {
var clock = new Clock();
ele.innerHTML = clock.toString();
window.setTimeout(function() {
clock.display(ele);
}, 1000);
};
}

// <span id="clock"> </span>
var clock = new Clock();
clock.display(document.getElementById("clock"));

我個人認為這個在web中很實用...所以推薦給大家啦...

相關(guān)文章

最新評論

瑞丽市| 磐安县| 增城市| 瑞昌市| 通海县| 伊春市| 宕昌县| 周宁县| 汾阳市| 梁河县| 莱芜市| 大渡口区| 孟连| 蕲春县| 廊坊市| 瑞安市| 漠河县| 甘谷县| 崇礼县| 安陆市| 右玉县| 盖州市| 禹州市| 华宁县| 罗江县| 桂东县| 民乐县| 舞钢市| 香河县| 乐亭县| 焦作市| 边坝县| 泽普县| 徐汇区| 喀喇| 南昌县| 衢州市| 文安县| 禹城市| 金溪县| 大丰市|