JS之点击按钮改变背景颜色

JS之点击按钮改变背景颜色.md


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>改变颜色title>
head>
<body>
	<input type="button" value="点击切换颜色" id="btn">
body>
<script>
	var btn = document.getElementById("btn");
	var body = document.body;
	let array = ["red", "blue", "yellow", "white", "black", "green", "orange","#FFF"];
	let index = 0;
	btn.onclick = function () {
		body.style.backgroundColor = array[index];
		index = (index + 1) % array.length;
	}

script>

html>

你可能感兴趣的:(JavaScript)