Adding warning when button is disabled

前端 未结 1 505
南旧
南旧 2021-01-27 06:58

I have this code:



        
1条回答
  •  生来不讨喜
    2021-01-27 07:25

    You've got plenty of code here. It's always better to provide a minimal solution. I tried to build a minimal solution for you.

    I's CSS only, the Javascript is only for clarification on how it works.

    var buttons = document.querySelectorAll(".btn");
    
    document.getElementById("toggle-disabled").addEventListener("click", function(e){
      for(let i = 0; i < buttons.length; i++){
        buttons[i].toggleAttribute("disabled");
      }
    });
    .btn-disabled-warning {
      display: none;
    }
    
    .btn[disabled] + .btn-disabled-warning {
      color: red;
      display: block;
    }

    The button is disabled :-(

    The button is disabled :-(

    0 讨论(0)
提交回复
热议问题