我有这种结构,当我检查清单中的内容时,我想隐藏div类“ categorydesc” ...
我怎样才能做到这一点?

<ul id="ul_layered_id_feature_10" class="col-lg-12">
<li id="layered_id_feature_10" class="checkbox" >
<input class="checkbox" name="layered_id_feature_10" id="layered_id_feature_10" type="checkbox">
<label for="layered_id_feature_10">test</label>
</li>
<li id="layered_id_feature_9" class="checkbox" >
<input class="checkbox" name="layered_id_feature_9" id="layered_id_feature_9" type="checkbox">
<label for="layered_id_feature_9">test</label>
</li>
</ul>

<div class="categorydesc">
<p>test</p>
</div>

最佳答案

您可以使用toggle方法更简单地执行此操作。



$(document).ready(function(){
	$('#checkbox').change(function(){
      	$('#container').toggle();
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id="checkbox"> Display
<hr/>
<div id="container" style="display:none;">
test
</div>

关于javascript - 选中复选框时如何隐藏div-JQuery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43865627/

10-10 21:02