我有一個複雜的表單,但我在嘗試構建一個jQuery以隱藏特定的DIVS集時褪色了大腦。我想要的是當複選框被選中時,這些div會隱藏起來。我有最接近的是這從複選框中隱藏一組div div選擇
jQuery(document).ready(function(jQ) {
jQ(".HideRow").click(function() {
if (jQ(this).is(":checked")) {
(jQ(this).closest('.wrapper').find('.hideme1, .hideme2, .hideme3').hide());
} else {
(jQ(this).closest('.wrapper').find('.hideme1, .hideme2, .hideme3').show());
}
});
});
.form-group {
clear: both;
}
.heading {
padding-right: 10px;
}
.header {
float: left !important;
padding-right: 10px;
}
.donothideme {
float: right !important;
padding-right: 10px;
padding-top: 8px;
}
.hideme1 {
Border: solid 2px blue;
padding: 10px 5px 5px 10px;
clear: both;
}
.hideme2 {
Border: solid 2px green;
padding: 10px 5px 5px 10px;
}
.hideme3 {
Border: solid 2px yellow;
padding: 10px 5px 5px 10px;
color: #000;
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="wrapper">
<div class="form-group">
<div class="heading">
<p></p>
<div class="header">
<h4>I do not want to hide</h4>
</div>
<div class="donothideme">
<label for="NWDCheckbox" class="checkme">Check me...</label>
<input name="Boxy" id="Boxy" value="Yes" class="HideRow CheckBox" type="checkbox">
</div>
</div>
</div>
<div class="hideme1">
<p>
I want To be Hidden
</p>
</div>
<div class="hideme2">
<p>
Me to
</p>
</div>
<div class="hideme3">
<p>
What about Me
</p>
</div>
<div class="form-group">
<div class="header">
<h4>I do not want to hide</h4>
</div>
<div class="donothideme">
<label for="NWDCheckbox" class="checkme">Check me...</label>
<input name="Boxy" id="Boxy" value="Yes" class="HideRow CheckBox" type="checkbox">
</div>
</div>
<div class="hideme1">
<p>
I want To be Hidden
</p>
</div>
<div class="hideme2">
<p>
Me to
</p>
</div>
<div class="hideme3">
<p>
What about Me
</p>
</div>
<div class="form-group">
<div class="header">
<h4>I do not want to hide</h4>
</div>
<div class="donothideme">
<label for="NWDCheckbox" class="checkme">Check me...</label>
<input name="Boxy" id="Boxy" value="Yes" class="HideRow CheckBox" type="checkbox">
</div>
</div>
<div class="hideme1">
<p>
I want To be Hidden
</p>
</div>
<div class="hideme2">
<p>
Me to
</p>
</div>
<div class="hideme3">
<p>
What about Me
</p>
</div>
</div>
上面的代碼是一個粗略的指南,我想實現 小提琴是這裏https://jsfiddle.net/gpLxaj8y/
你的小提琴似乎是單獨隱藏所有三組文檔。你只想爲每個盒子隱藏一套? – Elipzer