所以我有一個點擊功能來切換我的頁面上的按鈕。如果複選框被選中,我還有另一個功能可以爲按鈕添加一個類。我的問題是,如果類被添加到按鈕,然後點擊功能被觸發切換不會改變內聯樣式。在調用addClass後jQuery切換不起作用
$(".btn").click(function() {
$(".anotherBtn").toggle();
}
function getsCalledWhenCheckBoxIsChecked() {
$(".anotherBtn").addClass("hideBtn");
}
<style>
.hideBtn {
display: none !important;
}
</style>
這是一個更大的系統的一部分,我大大簡化了代碼,只是爲了顯示通常發生的事情。當使用開發人員工具以鉻形式查看頁面時,我可以看到,當添加「hideBtn」類時,內嵌樣式在切換時不會更改,但它在其他元素上執行。當班級被刪除時,它再次運作。
切換工作
<button class="anotherButton" style="display: inline-block;"></button>
<button class="anotherButton" style="display: none;"></button>
切換不會更改爲顯示:無
<button class="anotherButton hideBtn" style="display: inline-block;"></button>
<button class="anotherButton hideBtn" style="display: inline-block;"></button>
任何想法或幫助表示讚賞。
你沒有用id元素'anotherBtn'所以'$(「#anotherBtn」) ''必須是'$(「。anotherBtn」)',我認爲問題的發生是因爲'.hideBtn'的'display:none;'被標記爲'!important' – 2014-10-10 17:19:41
什麼是$(「btn」)' ? – showdev 2014-10-10 17:20:24
對不起,「#anotherBtn」是我寫這個問題的一個錯誤,沒有反映在實際的代碼中。 $(「btn」)只是觸發點擊功能的頁面上的另一個按鈕。 不幸的是,我不能分享問題的生產代碼,但我會在一個小提琴上顯示這個錯誤。 – 2014-10-10 17:23:50