我做了這個功能來隱藏不是按鈕文字顏色的 div。當我按下按鈕時似乎沒有任何反應,沒有隱藏任何類。我已經將 js 鏈接到 html 檔案中。我嘗試使用可見性:隱藏的類添加 toggleClass,但它似乎不起作用。我認為按鈕可能有問題
$(document).ready(function() {
$('#option_blue').click(function() {
$('.red', '.yellow').toggle();
})
})
.flex {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
gap: 5px;
}
.blue {
height: 100px;
width: 100px;
background-color: blue;
}
.red {
height: 100px;
width: 100px;
background-color: red;
}
.yellow {
height: 100px;
width: 100px;
background-color: yellow;
}
/*The style for my element boxes*/
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<button id="option_blue">blue</button>
<div class="flex">
<div class="blue">
<!--The divs are boxes containing content -->
</div>
<div class="red">
</div>
<div class="yellow">
</div>
<div class="blue">
</div>
<div class="red">
</div>
<div class="yellow">
</div>
</div>
uj5u.com熱心網友回復:
選擇器必須是唯一的字串,逗號在字串選擇器中:檔案鏈接。
$('.red, .yellow').toggle();
$(document).ready(function() {
$('#option_blue').click(function() {
$('.red, .yellow').toggle();
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<button id="option_blue">blue</button>
<div class="flex">
<div class="blue">
<!--The divs are boxes containing content -->
</div>
<div class="red">
red
</div>
<div class="yellow">
yellow
</div>
<div class="blue">
blue
</div>
<div class="red">
red
</div>
<div class="yellow">
yellow
</div>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/363791.html
標籤:查询
上一篇:如何通過AJAX將jquery物件資料發送到php?
下一篇:JQuery克隆元素
