我正在使用此代码在我的网页上的按钮上设置和删除已禁用的属性:
if (localStorage.buttonColor) {
document.getElementsByTagName('html')[0].className = localStorage.buttonColor;
var themeButtons = document.querySelectorAll(".theme");
for (var button in themeButtons) {
themeButtons[button].removeAttribute("disabled");
}
document.querySelector('button[name="' + localStorage.buttonColor + '"]').disabled = true;
}
但它给了我一条消息说:
Uncaught TypeError: Object 0 has no method 'removeAttribute'
有人可以就此提出建议吗?
答案 0 :(得分:3)
将disabled
视为属性,而不是属性:
themeButtons[button].disabled = false;