用js做个简单的时间表
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script type="text/javascript">
var dingShiqi = "";
function getNowDate() {
var nowDate = new Date();
var str = nowDate.getFullYear();
str += "-";
str += parseInt(nowDate.getMonth()) + 1;
str += "-";
str += nowDate.getDate();
str += " ";
str += nowDate.getHours();
str += ":";
if(nowDate.getMinutes() < 10) {
str+="0";
}
str += nowDate.getMinutes();
str += ":";
if(nowDate.getSeconds() < 10) {
str+="0";
}
str += nowDate.getSeconds();
document.getElementById("nowDate").value = str;
dingShiqi=setTimeout("getNowDate()", 1000);
}
function stopTime() {
window.clearTimeout(dingShiqi);
}
</script>
</head>
<body onLoad="getNowDate()">
当前时间:<input id="nowDate" name="nowDate" value="" />
<input type="button" value="得值" onClick="getNowDate()"/>
<input type="button" value="停止" onClick="stopTime()"/>
</body>
</html>