首页 > 解决方案 > 单击另一个按钮后如何设置按钮样式?

问题描述

我试图在单击按钮 1 后将按钮 2 更改为手指指针,所以我想知道是否有办法做到这一点,如果有请告诉我我要写什么代码注意:按钮 1 已经是我想要按钮 2 的手指指针单击按钮 1 后成为手指指针这是我的代码:

<input type="button" id="button1" type="submit" style="cursor: pointer; background-color:black;height: 45px; width: 150px; color:red;border-radius:10px;"value="first button" onclick="enableButton2()" /> 
<input type="button" id="button2" style="background-color:yellow; height: 45px;width: 225px;color:red;border-radius:10px;"value="second button" disabled />

标签: htmlcss

解决方案


用它 :

<script>
       function enableButton2(){
           var btn2 = document.getElementById('button2');
           btn2.setAttribute('disabled', false)
           btn2.style.cursor = 'pointer'
       }
   </script>
   
   <input type="button" id="button1" type="submit" style="cursor: pointer; background-color:black;height: 45px; width: 150px; color:red;border-radius:10px;" value="first button" onclick="enableButton2()" /> 
    <input type="button" id="button2" style="background-color:yellow; height: 45px;width: 225px;color:red;border-radius:10px;" value="second button" disabled="true" />

推荐阅读