3、Data对象

时间:2023-03-08 22:03:37
3、Data对象

1、创建part1.html

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Date对象的使用-时钟特效</title>
<script type="text/javascript">
window.onload=function(){
//获取第一个input标签
var inputone=document.getElementsByTagName("input")[0]; //给input标签添加点击事件
inputone.onclick=function(){
setTimeout("timeFun()",2000);
} //获取第2个input标签
var inputtwo=document.getElementsByTagName("input")[1]; //给input标签添加点击事件
var timestr;
inputtwo.onclick=function(){
timestr=setInterval("timeFun()",1000);
} //获取第2个input标签
var inputthree=document.getElementsByTagName("input")[2]; //给input标签添加点击事件
inputthree.onclick=function(){
clearInterval(timestr);
} } function timeFun(){
var date=new Date();
var year=date.getFullYear(); //获取四位年份
var month=date.getMonth()+1; //月份
var day =date.getDate(); //一个月中某一天,范围1-31
var week=date.getDay(); //星期
var hour=date.getHours(); //小时数,24进制
var minutes=date.getMinutes(); //分钟
var second=date.getSeconds(); //秒
var time=year+"年"
+month+"月"
+day+"日 星期"+week+" "
+hour+"时"+minutes+"分"+second+"秒";
console.log(time);
document.getElementsByTagName("div")[0].innerHTML=time; }
</script>
</head> <body>
<input type="button" value="3秒后出现"/>
<input type="button" value="动态时钟"/>
<input type="button" value="停止时钟"/>
<div id="time">
</div>
</body>
</html>

date对象实现时钟特效

2、效果图

3、Data对象

3、点击“三秒后出现”

3、Data对象

4、点击动态时钟

3、Data对象

5、点击停止时钟,时间将停止各秒刷新