两个interval函数是本次的重点 另外介绍了date匿名对象
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
// var date = new Date;
// document.write(date);
// //date = date.getTime(); //时间距离毫秒数
// document.write("<br>");
// var year = date.getFullYear(); //年份
// document.write(year);
// document.write("<br>");
// var mon = date.getMonth(); //月份0-11
// document.write(mon+1);
// document.write("<br>");
// // var day = date.getDay(); //某周的第几天
// // document.write(day);
// // document.write("<br>");
// var day = date.getDate(); // 某月的第几天
// document.write(day);
// document.write("<br>");
// var datr = date.toLocaleTimeString(); //一种标准的格式
// document.write(datr);
// document.write("<br>");
// document.write("<hr>");
// document.write("<br>");
// document.write("<br>");
function show (){
var date = new Date;
var stime = date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日"+date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒";
div = document.getElementById("div");
div.innerHTML = stime ;
}
window.onload = function(){
// var btn1 = document.getElementById("btn1");
// btn1.onclick = function(){
// //alert(stime);
// div = document.getElementById("div");
// div.innerHTML = stime ;
// }
}
function star (){
//返回变量是没用想到的
v = window.setInterval("show()","1000"); //1000毫秒 = 1 秒
}
function stop (){
window.clearInterval(v); //返回变量是没用想到的
//这两个interval函数是本次的重点 另外介绍了date匿名对象
}
</script>
</head>
<body>
<input type="button" id="btn1" value="显示时间" onclick="star()" />
<input type="button" id="btn2" value="时间暂停" onclick="stop()" /> <br />
<div id="div"></div>
</body>
</html>
动态变化:


被折叠的 条评论
为什么被折叠?



