本文目录一览:
- 1、想在jsp页面的某个中调用一个获取系统时间的,div的id设置成了time,写了一个js函数通过id调用不成功
- 2、用JavaScript语言设计:在页面上显示当前的时间,格式如图所示。
- 3、html显示时间代码
- 4、html中插入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文件 就怎么写 并不是一个文件只能一个函数