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文件 就怎么写 并不是一个文件只能一个函数

原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/309474.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小蓝小蓝
上一篇 2025-01-04 19:31
下一篇 2025-01-04 19:31

相关推荐

  • JS Proxy(array)用法介绍

    JS Proxy(array)可以说是ES6中非常重要的一个特性,它可以代理一个数组,监听数据变化并进行拦截、处理。在实际开发中,使用Proxy(array)可以方便地实现数据的监…

    编程 2025-04-29
  • Python简单数学计算

    本文将从多个方面介绍Python的简单数学计算,包括基础运算符、函数、库以及实际应用场景。 一、基础运算符 Python提供了基础的算术运算符,包括加(+)、减(-)、乘(*)、除…

    编程 2025-04-29
  • Python满天星代码:让编程变得更加简单

    本文将从多个方面详细阐述Python满天星代码,为大家介绍它的优点以及如何在编程中使用。无论是刚刚接触编程还是资深程序员,都能从中获得一定的收获。 一、简介 Python满天星代码…

    编程 2025-04-29
  • Python海龟代码简单画图

    本文将介绍如何使用Python的海龟库进行简单画图,并提供相关示例代码。 一、基础用法 使用Python的海龟库,我们可以控制一个小海龟在窗口中移动,并利用它的“画笔”在窗口中绘制…

    编程 2025-04-29
  • 解析js base64并转成unit

    本文将从多个方面详细介绍js中如何解析base64编码并转成unit格式。 一、base64编码解析 在JavaScript中解析base64编码可以使用atob()函数,它会将b…

    编程 2025-04-29
  • Node.js使用Body-Parser处理HTTP POST请求时,特殊字符无法返回的解决方法

    本文将解决Node.js使用Body-Parser处理HTTP POST请求时,特殊字符无法返回的问题。同时,给出一些相关示例代码,以帮助读者更好的理解并处理这个问题。 一、问题解…

    编程 2025-04-29
  • Python樱花树代码简单

    本文将对Python樱花树代码进行详细的阐述和讲解,帮助读者更好地理解该代码的实现方法。 一、简介 樱花树是一种图形效果,它的实现方法比较简单。Python中可以通过turtle这…

    编程 2025-04-28
  • t3.js:一个全能的JavaScript动态文本替换工具

    t3.js是一个非常流行的JavaScript动态文本替换工具,它是一个轻量级库,能够很容易地实现文本内容的递增、递减、替换、切换以及其他各种操作。在本文中,我们将从多个方面探讨t…

    编程 2025-04-28
  • Python大神作品:让编程变得更加简单

    Python作为一种高级的解释性编程语言,一直被广泛地运用于各个领域,从Web开发、游戏开发到人工智能,Python都扮演着重要的角色。Python的代码简洁明了,易于阅读和维护,…

    编程 2025-04-28
  • 用Python实现简单爬虫程序

    在当今时代,互联网上的信息量是爆炸式增长的,其中很多信息可以被利用。对于数据分析、数据挖掘或者其他一些需要大量数据的任务,我们可以使用爬虫技术从各个网站获取需要的信息。而Pytho…

    编程 2025-04-28

发表回复

登录后才能评论