gpt4 book ai didi

javascript - jQuery 在选中复选框时隐藏 div,在未选中时显示

转载 作者:技术小花猫 更新时间:2023-10-29 12:03:54 25 4
gpt4 key购买 nike

我试图在用户单击复选框时隐藏 div,并在用户取消选中该复选框时显示它。HTML:

<div id="autoUpdate" class="autoUpdate">
content
</div>

jQuery:

<script>
$('#checkbox1').change(function(){
if (this.checked) {
$('#autoUpdate').fadeIn('slow');
}
else {
$('#autoUpdate').fadeOut('slow');
}
});
</script>

我很难让它工作。

最佳答案

确保使用 ready 事件。

代码:

$(document).ready(function(){
$('#checkbox1').change(function(){
if(this.checked)
$('#autoUpdate').fadeIn('slow');
else
$('#autoUpdate').fadeOut('slow');

});
});

关于javascript - jQuery 在选中复选框时隐藏 div,在未选中时显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14757792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com