我有以下 HTML:
<button class="Blue" id="theme" onclick="setThemeColor(this)">#</button>
以及以下功能:
function setThemeColor(button) {
localStorage.themeColor = // I need to set it here but I am not sure how
// if the class is Blue it needs to be Black
// if the class is Black it needs to be Blue
document.getElementsByTagName('html')[0].className = //
// I need to change the button class
}
我怎样才能做到这一点:
- 如果按钮类为蓝色,则单击它将类更改为黑色,html 类名更改为蓝色
- 如果按钮类为黑色,则单击它将类更改为蓝色,html 类名更改为黑色