我有一个复杂的表单,但我在尝试构建一个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