該程序應該改變給定顏色數組的HTML主體的背景顏色。但顏色並不像它應該顯示的那樣?點擊事件不能在Javascript中工作
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>I Can Click A Rainbow</title>
</head>
<body>
<button id="button">click me</button>
<script src="js/script.js"></script>
</body>
</html>
var button = document.getElementById("button");
var rainbow = ["red", "orange", "green", "blue", "indigo", "violet"];
function change() {
"use strict";
document.body.style.background = rainbow[Math.floor(7 * Math.random())];
}
button.addEventListener("click change");
控制檯中是否有錯誤? – Goose