如何从页面上的按钮元素中删除禁用

How can I remove disabled from a button element on my page?

本文关键字:元素 删除 按钮      更新时间:2023-09-26

我正在使用此代码来设置和删除网页上按钮上的禁用属性:

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;