我正在做一個問答游戲,(請注意,答案選項由錨標簽組成)
我在 options.forEach eventListener 中添加了代碼,它將選項指標事件設定為“none”,這樣一旦單擊一個答案,您就無法選擇另一個答案。
// 選項 BTN 事件
// Only select one option
if ("clicked") {
options.forEach((op) => {
op.style.pointerEvents = "none";
});
}
}); }); 我嘗試:制作 btn.eventListener (這是下一個按鈕),將 bg-color 設定回灰色,并設定選項 style.pointerEvents = "auto"; 以便您可以單擊下一個問題的選項。
btn.addEventListener("click", () => {
currentQuestion = 1;
getQuestion();
options.forEach((op) => {
op.style.backgroundColor = $btnCol;
op.style.pointerEvents = "auto";
});
});
問題:此代碼用于重新啟用再次單擊選項的功能,但我希望懸停效果也能恢復。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
我認為這是因為您在 javascript 中設定了背景顏色,并將其應用于行內級別 (style="background-color: red;") 中的元素,這在 extarnel css 檔案的優先級方面是之前的。
為了更好的解釋:這里
!important您應該在外部 css 檔案中添加陳述句的解決方案。
這是一個例子:
.a {
background-color: red;
}
.a:hover {
background-color: blue;
}
.b {
background-color: red;
}
.b:hover {
background-color: blue !important;
}
<div class="a" style="background-color: red;">without !important</div>
<div class="b" style="background-color: red;">with !important</div>
正如您在此處看到的!important那樣,懸停時沒有顏色的顏色不會改變,但帶有顏色的顏色實際上正在改變。
因此,您應該!important在懸停部分中添加代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/482956.html
標籤:javascript
上一篇:將附加html添加到字串中
