如何使用javascript更改按钮的可见/隐藏属性?

如何使用javascript更改按钮的可见/隐藏属性?,javascript,Javascript,在我的页面上,我有以下主题更改按钮: <button class="small theme" name="darkBlue" onclick="setThemeColor(this)"> <span style="color: white; font-weight: bold;">#</span> </button> <button class="small theme" name="black" onclick="setThemeCo

在我的页面上,我有以下主题更改按钮:

<button class="small theme" name="darkBlue" onclick="setThemeColor(this)">
   <span style="color: white; font-weight: bold;">#</span>
</button>
<button class="small theme" name="black" onclick="setThemeColor(this)">
   <span style="color:black; font-weight:bold;">#</span>
</button>

#
#
我有一个javascript:

   <script type="text/javascript">
      if (localStorage.themeColor) {
         document.getElementsByTagName('html')[0].className = localStorage.themeColor;
      }

      function setThemeColor(button) {
         localStorage.themeColor = button.name;
         document.getElementsByTagName('html')[0].className = button.name;
         var themeButtons = document.querySelectorAll(".theme");
         for (var themeButton in themeButtons) {
             themeButtons[themeButton].disabled = false;
         }
        button.disabled = true;
      }
   </script>

if(localStorage.themeColor){
document.getElementsByTagName('html')[0]。className=localStorage.themeColor;
}
功能设置颜色(按钮){
localStorage.themeColor=button.name;
document.getElementsByTagName('html')[0].className=button.name;
var themeButtons=document.queryselectoral(“.theme”);
for(按钮中的按钮变量){
themeButtons[themeButton].disabled=false;
}
button.disabled=true;
}
这总是显示两个按钮,但我想这样做,而不是 当前按钮被禁用,则该按钮不可见。谁能
建议如何执行此操作?

按钮[themeButton].style.visibility='hidden'
?我是否也可以执行button.style.visibility='visible';对于下面的部分,我认为你的例子是错误的。我需要一个按钮变为可见,另一个按钮变为不可见(在我刚刚按下它之后,或者如果localstorage设置为该主题)。如果该主题有localstorage值,我还需要隐藏相应的按钮,以便我可以选择另一个主题。然后对需要可见的主题使用Visibility=visible,和可见性=为你想要隐藏的人隐藏。这似乎根本不起作用。设置可见性是否正确?我的首选是使用display属性display=“none”/“block”/“inline”等,但这有其自身(许多)缺陷。至于为什么它不起作用,我忘了将.style部分放在可见性行上,例如button.style.visibility。
function setThemeColor(button) {
    localStorage.themeColor = button.name;
    document.getElementsByTagName('html')[0].className = button.name;
    var themeButtons = document.querySelectorAll(".theme");
    for (var themeButton in themeButtons) {
        themeButtons[themeButton].disabled = false; // Re-included from original code
        themeButtons[themeButton].style.visibility="visible" // Corrected from original answer
    }
    button.disabled = true;
    button.style.visibility="hidden" // Added/Moved from above after noted I'd messed up the logic
}