博主信息
博文 27
粉丝 0
评论 0
访问量 27027
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
随机色、倒计时-第五期0328作业
不乖的博客
原创
762人浏览过

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			*{
				margin: 0;
				padding: 0;
			}
			div{
				width: 500px;
				height: 500px;
				margin: 100px auto;
			}
			span{
				display: inline-block;
				width: 50px;
				height: 50px;
				font-size: 30px;
				text-align: center;
				line-height: 50px;
				color: pink;
			}
			a{
				text-decoration: none;
				color: red;
			}
		</style>
	</head>
	<body>
		<button onclick="bg_Color()">点击切换背景色</button>
		<div>
			<span>8</span>秒后跳转至<a href="https://www.baidu.com">百度</a>
		</div>
		<script>
			/*【案例2】随机色
			     【案例3】倒计时
			*/
			
			/*Math.random()产生[0,1)不包含1的数*/
			var num=Math.random();
			console.log(num);
			function bg_Color(){
				var str='#';
				var r=Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10);
				var g=Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10);
				var b=Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10);
				str+=r+g+b;
				console.log(str);
				document.getElementsByTagName('body')[0].style.backgroundColor=str;
			}
			
			/*【案例3】倒计时*/
			var i=8;
			function CountDown(){
				var Sp=document.getElementsByTagName('span')[0];
				if(i>1){
					i--;
					Sp.innerHTML=i;
					console.log(i);  
				}else{
					window.location.href='https://www.baidu.com';
				}
			}
			setInterval('CountDown()',1000);
		</script>
	</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学