javascript - 选中复选框时如何隐藏div - JQuery

标签 javascript jquery html css checkbox

我有这个结构,当我从 list 中检查某些内容时,我想隐藏 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/

相关文章:

javascript - 在自定义 JQuery 验证规则中读取非元素值的正确方法是什么?

javascript - AngularJS,使用对象 ID 获取范围

javascript - 单击选项卡,选项卡消失

html - 即使内容不同,如何让我的 div 空间保存

javascript - 街景 API 不返回街景

javascript - 如何根据 javascript 或 jquery 中的 highcharts 的 x,y 对中的日期对数组进行排序

jQuery追加DIV然后动画

javascript - 与 script 和prototype.js 冲突

html - 为什么文本出现在它的容器外面?

html - 通过 CSS 调整背景大小