js自动创建div每秒创建一个div,div由a-z创建,穿建到z时结束创建,并让div内的颜色随机变化

<!DOCTYPE html>
<html>

<head>
	<title>页面效果</title>`
	<style>
		.dv {
			display: inline-block;
			width: 80px;
			height: 80px;
			border: 2px solid #000;
			border-radius: 5px;
			font-size: 25px;
			text-align: center;
			line-height: 80px;

		}
	</style>

</head>

<body>

</body>

<script>
	var num = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	var a = 0
	//var count=65
	var js = setInterval(function () {
		//创建一个div

		var div = document.createElement('div');

		div.className = 'dv'//为div创建属性class = "dv"	
		div.innerHTML = num[a++]
		// div.innerHTML = String.fromCharCode(count++)
		document.querySelector("body").appendChild(div)
		aa()
		// if (count<92) 
		if (a >= 26) {
			clearInterval(js)
		}

	}, 1000)//js创建div,每隔一秒创建一个


	function aa() {

		var b = document.querySelectorAll('.dv');
		var a = Math.floor(Math.random() * b.length);
		b[a].style.background = bb()
		setTimeout("aa()", 1000);//每隔一秒后重新运行,定时器

	}
	function bb(){
		var hex = Math.floor(Math.random() * 16777216).toString(16);
		while (hex.length < 6) {
			hex = '0' + hex;
		}
		hex='#'+hex
		return hex
	}//随机颜色


</script>

</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值