Blogger Information
Blog 38
fans 0
comment 3
visits 43826
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js基础学习-5秒倒计时
意外的博客
Original
842 people have browsed it
<!DOCTYPE html>
<html>
<head>
	<title>日期对象</title>
</head>
<body>

<button onclick="getDates()">点击获取时间</button>
<button ondblclick="getDates()">双击也获取时间</button>
<div>
	<span>5</span>
	<a href="http://www.php.cn/">php中文网</a>
</div>

<script type="text/javascript">
	//获取当前日期;
	var d= new Date();
function getDates(){
		// document.write(d);
	var year=d.getFullYear();	//获取当前日期的年份;
	var month=d.getMonth()+1;	//获取当前日期的月份;
	var date=d.getDate();	//获取当前日期的日;
	var x=year+'-'+month+'-'+date;
	document.write(x+' ')

	var h=d.getHours();		//获取小时(0-23之间的整数)
	var m=d.getMinutes();   //获取分钟(0-59之间的整数)
	var s=d.getSeconds();  	//获取秒(0-59之间的整数)
	var y=h+':'+m+':'+s;
	document.write(y)
}

//5秒倒计时练习
//如果将i=4放在函数里面,那么setInterval调用,每次都会将i=4给赋值
var i=10;
function time(){
var Espan=document.getElementsByTagName('span')[0];
	if (i>0) {
		//改变i的内容;
		Espan.innerHTML=i;
		i--;
	}else{
		window.location.href ="http://www.php.cn";
	}
}
//刷新时间;
//setInterval("time()",1000)

 // 倒计时思路:在函数外部赋予变量一个数字(与需要倒计时的数字相等即可);
// 	创建一个函数,首先获取倒计时这个数字的标签;判断变量这个数字是否大于0;
	// 大于0就修改这个数字(通过--计算),
	// 否则就跳转到你需要执行的步骤;然后函数外部调用刷新时间;

</script>
</body>
</html>


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post