我需要將按鈕的背景顏色從深色更改為綠色
<button class="btn btn-dark" id="btn" th:attr="onclick=|vote('${listAnswer.answer_id}',' 1')|"><i class="fa fa-star fa-2x" ></i>UpVote</button>
我嘗試使用以下代碼將按鈕的背景顏色從深色更改為綠色。這沒用。請幫我
function vote(answerId,rateValue){
alert(rateValue);
axios.post('/saveRatings?answerId=' answerId '&rateValue=' rateValue, {
})
.then(function(response){
document.getElementById("btn").style.background-color='green';
})
}
uj5u.com熱心網友回復:
插入
document.getElementById("btn").style.background-color='green';
用戶
document.getElementById("btn").style.backgroundColor = 'green';
uj5u.com熱心網友回復:
單擊按鈕后,它的狀態變為“活動”,您可以使用 css 將按鈕的顏色更改為您想要的任何顏色。您需要做的就是使用 ":active" 選擇器添加一個 css 規則。 https://www.w3schools.com/cssref/sel_active.asp https://www.freecodecamp.org/news/css-button-style-hover-color-and-background/ 基本上:
button:active { color: red; }
uj5u.com熱心網友回復:
也可以代替document.getElementById("btn").style.background-color您使用document.getElementById("btn").style['background-color']
uj5u.com熱心網友回復:
你可以試試這個方法
<button class="btn btn-dark" id="btn" th:attr="onclick=|vote('${listAnswer.answer_id}',' 1')|"><i class="fa fa-star fa-2x" ></i>UpVote</button>
JS
const btn = document.getElementById('btn');
btn.addEventListener('click', function onClick() {
btn.style.backgroundColor = 'green';
btn.style.color = '(Color whatever you want)';
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/486780.html
標籤:javascript html css axios 百里香叶
