实现效果:有2个按钮,点击其中任意一个按钮改变其背景色,另外一个恢复默认色

function sure(key){

          var bt1 = document.getElementById('bt1');
          var bt2 = document.getElementById('bt2');
          bt1.style.backgroundColor="";
          bt2.style.backgroundColor="";
          if(key==1){
              bt1.style.backgroundColor="red";
          }else {
              bt2.style.backgroundColor="red";
          }
      }

<input type="button" id="bt1" onclick="return sure(1)" value="按钮1">
<input type="button" id="bt2" onclick="return sure(2)" value="按钮2">

猜你喜欢

转载自blog.csdn.net/qq_31118837/article/details/80976031
今日推荐