我有多個按鈕,當單擊一個喜歡的按鈕時,我希望字體真棒圖示也能切換,但是,我設定字體真棒圖示的方式就消失了,但我可以看到類的變化。不知道從這里去哪里。
$("button").click(function() {
$('#like' this.id).toggleClass("fa-regular fa-thumbs-up");
});
<script src="https://kit.fontawesome.com/317f6467e2.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="like-button btn" id="1">
<i class="fa-solid fa-thumbs-up" id="like1"></i>
</button>
<button class="like-button btn" id="2">
<i class="fa-solid fa-thumbs-up" id="like2"></i>
</button>
uj5u.com熱心網友回復:
如果您想更改圖示/樣式,只需添加其他類即可toggleClass
:
$("button").click(function() {
$('#like' this.id).toggleClass("fa-solid fa-thumbs-up fa-regular fa-thumbs-up");
});
<script src="https://kit.fontawesome.com/317f6467e2.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="like-button btn" id="1">
<i class="fa-solid fa-thumbs-up" id="like1"></i>
</button>
<button class="like-button btn" id="2">
<i class="fa-solid fa-thumbs-up" id="like2"></i>
</button>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/497886.html
標籤:javascript html jQuery css 字体真棒
上一篇:如何將多個按鈕選擇添加到Div