您好,欢迎访问一九零五行业门户网

javascript时间自动刷新实现原理与步骤_javascript技巧

项目结构:
运行效果:
=========================================================
代码部分:
=========================================================
/clock/webcontent/index.jsp
复制代码 代码如下:
string path = request.getcontextpath();
string basepath = request.getscheme() + ://
+ request.getservername() + : + request.getserverport()
+ path + /;
%>
insert title here
/clock/webcontent/js/clock/clock.js
复制代码 代码如下:
/**
* 时间显示
* @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() this.minute = date.getminutes() this.second = 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);
};
}
//
var clock = new clock();
clock.display(document.getelementbyid(clock));
我个人认为这个在web中很实用...所以推荐给大家啦...
其它类似信息

推荐信息