<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>日期</title>
<SCRIPT language="JavaScript">
var handle;
function func(x) {
clearInterval(handle);
var p = new Date();
document.myform.myclock.value = (1900 + p.getYear()) + "年" + (p.getMonth() + 1) + "月" + p.getDate() + "日";
}
function func2(x) {
handle = setInterval("disptime()",1000);
}
function disptime() {
var time = new Date(); //获得当前时间
var hour = time.getHours(); //获得小时、分钟、秒
var minute = time.getMinutes();
var second = time.getSeconds();
var apm = "AM"; //默认显示上午: AM
if (hour > 12) {
hour = hour - 12;
apm = "PM";
}
if (minute < 10)
minute = "0" + minute;
if (second < 10)
second = "0" + second;
document.myform.myclock.value = hour + ":" + minute + ":" + second + " " + apm;
}
</SCRIPT>
</head>
<body>
<form name="myform">
<input name="myclock" onmouseover="func(this)" onmouseout="func2(this)" type="text" value="">
</form>
</body>
</html>
使用JavaScript中的date()函数和利用mouseover()事件实现简单的日期时间变换
最新推荐文章于 2023-04-25 11:12:23 发布