我使用此代码来设置和删除网页上按钮的禁用属性:
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'
有人可以给我这方面的建议吗?
最佳答案
将 disabled
视为属性,而不是属性:
themeButtons[button].disabled = false;
关于javascript - 如何从页面上的按钮元素中删除禁用状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19316037/