通過單擊禁用任何按鈕後,該按鈕看起來像禁用了按鈕,但接受更多的點擊。我注意到頁面中沒有<form>
,但添加<form>
似乎並不重要。已禁用的按鈕指示殘疾,但接受點擊
https://jsfiddle.net/3y1dn29v/
爲什麼?
function tally(card, suit) {
cards += card;
suits += suit;
alert("btn" + card + suit);
disableButton("btn" + card + suit)
}
function disableButton(button) {
document.getElementById(button).setAttribute("class", "button disabled");
var x = document.getElementById(button).getAttribute("class");
alert(x);
}
var suits = "";
var cards = "";
.button {
color: white;
font-size: 16px;
border-radius: 25px;
}
.disabled {
opacity: 0.6;
cursor: not-allowed;
}
<div id="Spades" class="tabcontent">
<h3>♠</h3>
<div class="btn-group">
<button id="btnAS" class="button" onclick='tally("A","S")'>A</button>
<button id="btnKS" class="button" onclick='tally("K","S")'>K</button>
<button id="btnQS" class="button" onclick='tally("Q","S")'>Q</button>
<button id="btnJS" class="button" onclick='tally("J","S")'>J</button>
</div>
</div>
爲什麼呢?因爲你只是 - 在你的代碼中無處設置被點擊的按鈕具有'disabled' **屬性**。 –
是的,我在函數'disableButton()'中做過。實際上,如果你從課堂上刪除「按鈕」,你會得到相同的結果。 – zerowords
不,你有沒有:)有一個**光標風格**'不允許'和一個實際**禁用**按鈕的巨大差異。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button或一個快速的Goog:「html js如何禁用按鈕」會導致您找到合適的解決方案。 –