我有以下 HTML:
<button name="darkBlue" onclick="setThemeColor(this.name)">Blue</button>
<button name="black" onclick="setThemeColor(this.name)">Black</button>
这个脚本:
if (localStorage.buttonColor) {
var themeButtons = document.querySelectorAll(".theme");
for (var button in themeButtons) {
themeButtons[buttons].removeAttribute("disabled");
}
// I need here to disable the button with the name that matches localstorage name
}
我已经有了从所有按钮中删除禁用的方法。但是,在不使用 jQuery 的情况下,如何禁用与 localStorage.buttonColor 同名的按钮?
我也可以在for (var button in themeButtons)
循环中完成所有这些吗?如果我能做到这一点,它可能是一个更干净的解决方案。