它应该接受choice变量作为其输入表达式。
对于每种情况,选择应该等于可以选择的可能值之一,即白色,黑色,紫色,黄色或迷幻色。
对于每种情况,应运行update()函数,并传递两个颜色值,第一个颜色值为背景颜色,第二个颜色值为文本颜色。请记住,颜色值是字符串,因此需要用引号括起来。
<h1>themeUpdate</h1>
</div>
<script>
const select = document.querySelector('select');
const html = document.querySelector('.output');
select.onchange = function () {
let choice = select.value;
switch (choice) {
case 'black':
updateTheme('black', 'white');
break;
case 'white':
updateTheme('white', 'black');
break;
case 'purple':
updateTheme('purple', 'white');
break;
case 'yellow':
updateTheme('yellow', 'darkgray');
break;
case 'psychedelic':
updateTheme('lime', 'purple');
break;
}
}
function updateTheme(bgColor, textColor) {
html.style.backgroundColor = bgColor;
html.style.color = textColor;
}
</script>