我正在製作一個網站我想制定一個規則,如果"all"
div被點擊,"display: none"
<div>
將通過刪除它的'none'
類出現。我的代碼不工作,我不明白爲什麼。點擊一個元素刪除其他元素類
我已經嘗試了一切,我知道,搜索網絡的問題的答案,我找不到任何可以幫助我處理這個特定情況。
var check1;
var check2;
$("#btn-1").click(function() {
check1 = 1;
});
$("#btn-2").click(function() {
check2 = 1;
});
if (check1 == 1 && check2 == 1) {
$("#btn-3").removeClass("none");
}
div {
position: fixed;
padding: 20px;
background-color: lightblue;
width: 150px;
}
#btn-1 {
bottom: 0;
}
#btn-2 {
bottom: 0;
left: 250px;
}
#btn-3 {
top: 0;
}
.none {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="btn-1">
</div>
<div id="btn-2">
</div>
<div id="btn-3" class="none">
</div>
你有沒有試圖把'if(check1 == 1 && check2 == 1){$(「#btn-3」)。removeClass(「none」); }'在函數中並在點擊按鈕的點擊事件中調用它? – Krusader
@Krusader我沒有從內部點擊事件中調用它,因爲我認爲javascript只會在循環中運行並檢查是否有任何變化。我現在知道我的錯誤 –