[英]jQuery input checkbox to hide div content
I am not sure what is happening but I am not able to make my jquery hide a div when check box is checked. 我不确定发生了什么,但是当复选框被选中时,我无法使我的jQuery隐藏一个div。 Super simple and I am not sure why it isn't working.
超级简单,我不确定为什么不起作用。 Thanks for the help here is the code.
感谢您的帮助,这里是代码。
<input type="checkbox" id="yesall">
<div id="noshow">
content
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#yesall').change(function(){
if (this.checked)
$('#noshow').fadeOut('slow');
else {
$('#noshow').show();
}
});
});
</script>
thank you guys I am thinking I am missing something super simple here. 谢谢大家,我想我在这里缺少一些超级简单的东西。
The $(document).ready()
function only runs once when the webpage is ready. $(document).ready()
函数仅在网页准备就绪时运行一次。 That might be the cause of your problem. 那可能是造成您问题的原因。 You could try:
您可以尝试:
$(function(){
$('#yesall').change(function(){
if($(this).prop("checked")) {
$('#noshow').show();
} else {
$('#noshow').hide();
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.