到目前为止,当我单击按钮时,我可以让页面上的背景颜色发生变化,但只能更改为 1 组颜色。
我希望能够继续点击按钮并每次获得不同的颜色或至少几种不同的预设颜色。
这就是我现在所拥有的。
<button type="button" onclick="myFunction()">Change Color</button>
<script>
function myFunction()
{
document.body.style.backgroundColor= "green";
}
</script>
原文由 Tando 发布,翻译遵循 CC BY-SA 4.0 许可协议
这个功能应该工作。先生成一个1到10之间的随机数,随着变化有switch