我已经为这些按钮编写了这段代码,因此当我单击它们时,背景颜色会发生变化,但它不起作用。问题是什么?
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="styles.css">
<title>JavaScript Background Color Switcher</title>
</head>
<body>
<div class="canvas">
<h1>Color Scheme Switcher</h1>
<span class="button" id="grey"></span>
<span class="button" id="white"></span>
<span class="button" id="blue"></span>
<span class="button" id="yellow"></span>
</div>
<script src="app.js"></script>
</body>
</html>
JS File:
document.querySelector('.button').addEventListener('click', function btn (id) {
document.body.style.background = id
})
慕姐4208626
慕虎7371278
德玛西亚99
相关分类