Disable buttons but keep style.

huangapple go评论62阅读模式
英文:

Disable buttons but keep style

问题

Is there a way to disable buttons but keep the default style? Not have them greyed out? currently, the buttons are disabled correctly but are shown as greyed out. I have found a similar question however they were using jQuery and I need to use vanilla JavaScript.

function disableAnswers() {
    for (let i = 0; i < answers.length; i++) {
        answers[i].disabled = true;
    }
    nextQ.classList.remove('hidden');
}
英文:

Is there a way to disable buttons but keep the default style? Not have them greyed out? currently, the buttons are disabled correctly but are shown as greyed out. I have found a similar question however they were using jQuery and I need to use vanilla JavaScript.

function disableAnswers() {
    for (let i = 0; i &lt; answers.length; i++) {
        answers[i].disabled = true;
    }
    nextQ.classList.remove(&#39;hidden&#39;);
}

答案1

得分: 2

你可以使用简单的CSS来处理这个:

button:disabled {
  color: initial;
}
<button disabled>Button</button>
英文:

You can handle this with simple CSS:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

button:disabled {
  color: initial;
}

<!-- language: lang-html -->

&lt;button disabled&gt;Button&lt;/button&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月14日 05:28:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244957.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定