您的位置:

clock.js的简单介绍

clock.js的简单介绍

更新:

本文目录一览:

想在jsp页面的某个中调用一个获取系统时间的,div的id设置成了time,写了一个js函数通过id调用不成功

时间js代码:Clock.js文件

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();

this.toString = function() {

return this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;

};

this.toSimpleDate = function() {

return this.year + "-" + this.month + "-" + this.date;

};

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);

};

}

需要显示时间的页面

SCRIPT src="js/Clock.js" type=text/javascript/SCRIPT //引入Clock.js文件,注意路径

label id=clock/label //放入标签,插入时间

SCRIPT type=text/javascript //实例化clock对象

var clock = new Clock();

clock.display(document.getElementById("clock"));

/SCRIPT

用JavaScript语言设计:在页面上显示当前的时间,格式如图所示。

script

function tick() {

var hours, minutes, seconds, xfile;

var intHours, intMinutes, intSeconds;

var today;

var Clock = document.getElementById('Clock');

today = new Date();

intHours = today.getHours();

intMinutes = today.getMinutes();

intSeconds = today.getSeconds();

if (intHours == 0) {

hours = "12:";

xfile = "午夜 ";

} else if (intHours 12) {

hours = intHours+":";

xfile = "上午 ";

} else if (intHours == 12) {

hours = "12:";

xfile = "正午 ";

} else {

intHours = intHours - 12

hours = intHours + ":";

xfile = "下午 ";

}

if (intMinutes 10) {

minutes = "0"+intMinutes+":";

} else {

minutes = intMinutes+":";

}

if (intSeconds 10) {

seconds = "0"+intSeconds+" ";

} else {

seconds = intSeconds+" ";

}

timeString = xfile+hours+minutes+seconds;

Clock.innerHTML = timeString;

now = new Date(),hour = now.getHours()

if(hour 6){Clock.innerHTML =timeString+",明天不用上班了吗?"}

else if (hour 8){Clock.innerHTML =timeString+",全新的一天!"}

else if (hour 10){Clock.innerHTML =timeString+",早安!"}

else if (hour 12){Clock.innerHTML =timeString+",加油,快午饭了!"}

else if (hour 14){Clock.innerHTML =timeString+",中午外面的太阳大吗?"}

else if (hour 16){Clock.innerHTML =timeString+",喝杯咖啡提提神!"}

else if (hour 18){Clock.innerHTML =timeString+",加油,快下班了!"}

else if (hour 19){Clock.innerHTML =timeString+",下班了,回家注意安全!"}

else if (hour 22){Clock.innerHTML =timeString+",晚上好!"}

else if (hour 24){Clock.innerHTML =timeString+",夜深了!祝你做个好梦!"}

window.setTimeout("tick();", 100);

}

window.onload = tick;

/script

html

body

您好,font color="#FF0000"现在时间是/fontspan id="Clock" align="center" style="font-size: 12; color:#FF0000"/span

/body

/html

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

你会满意的!!

html显示时间代码

时间js代码:Clock.js文件

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();

this.toString = function() {

return this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;

};

this.toSimpleDate = function() {

return this.year + "-" + this.month + "-" + this.date;

};

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);

};

}

需要显示时间的页面

SCRIPT src="js/Clock.js" type=text/javascript/SCRIPT //引入Clock.js文件,注意路径

label id=clock/label //放入标签,插入时间

SCRIPT type=text/javascript //实例化clock对象

var clock = new Clock();

clock.display(document.getElementById("clock"));

/SCRIPT

html中插入js文件的问题

这个很简单 你只要把html中script/script里面的内容剪切出来存在clock.js中

然后在html的head/head这对标签中加入这句话script src="clock.js"/script就行了

你本来在script/script 怎么写的 在js文件 就怎么写 并不是一个文件只能一个函数

clock.js的简单介绍

本文目录一览: 1、想在jsp页面的某个中调用一个获取系统时间的,div的id设置成了time,写了一个js函数通过id调用不成功 2、用JavaScript语言设计:在页面上显示当前的时间,格式如图

2023-12-08
javascript入门笔记1的简单介绍

2022-11-18
python使用笔记23的简单介绍

2022-11-10
javascript简要笔记,JavaScript读书笔记

2022-11-17
c到c语言笔记的简单介绍

2022-11-24
java包笔记,Java语言包

2022-11-18
印象笔记记录java学习(Java成长笔记)

2022-11-12
java客户端学习笔记(java开发笔记)

2022-11-14
重学java笔记,java笔记总结

2022-11-23
java基础知识学习笔记一,Java基础笔记

2022-11-21
htmljs编程笔记(html代码笔记)

本文目录一览: 1、html代码和JS代码有什么区别 2、如何在html中调用js函数 3、JavaScript学习笔记之数组基本操作示例 4、HTML5初学者笔记 5、《web前端笔记7》js字符—

2023-12-08
java学习笔记(java初学笔记)

2022-11-14
java基础第一天学习笔记(java课程笔记)

2022-11-09
重拾python笔记三的简单介绍

2022-11-13
java笔记,大学java笔记

2022-11-28
js修改cssimportant的简单介绍

本文目录一览: 1、js如何直接修改css里面的属性值呢? 2、笔记:JS设置CSS样式的几种方式 3、如何用JS修改已加载的CSS样式表样式? 4、JS修改CSS设置的样式 5、如何使用jquery

2023-12-08
发篇java复习笔记(java课程笔记)

2022-11-09
java笔记,尚硅谷java笔记

2022-12-01
java方向综合笔试题的简单介绍

2022-11-23
Markdown笔记的全方位介绍

2023-05-18