根据复选框值切换div [英] Toggle div based on checkbox value
本文介绍了根据复选框值切换div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不确定该如何完成.我想要做的是基于复选框值隐藏div.这是我的切换代码.
I'm not sure how to accomplish this. What I want to do is to hide a div based on a checkbox value. This is my code for the toggle.
感谢任何帮助
.始终是复选框
.always is the checkbox
$(document).ready(function () {
$('.always').click(function () {
$('#dates').toggle();
});
});
推荐答案
.toggle()
需要一个布尔值也是如此,
.toggle()
takes a boolean as well, like this:
$(function () {
$('.always').change(function () {
$('#dates').toggle(!this.checked);
}).change(); //ensure visible state matches initially
});
您可以在此处进行测试.我假设在上面,如果选中了.always
,您想隐藏#dates
,这就是它的作用.
You can test it out here. I assume in the above you want the #dates
hidden if .always
is checked, that's what it'll do.
这篇关于根据复选框值切换div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文