gpt4 book ai didi

javascript - 选中复选框时如何更改 DIV 的颜色?

转载 作者:行者123 更新时间:2023-11-29 19:41:46 25 4
gpt4 key购买 nike

我想在选中复选框时更改 DIV 的颜色。我想在 jQuery 中执行此操作。我试过这个:

 if($('#checkboxTest').is(':checked'))
{
$('.alertWrapper').css('background-color', 'blue');
}

但它不起作用..有什么帮助吗?

最佳答案

您需要使用 .change() 跟踪复选框状态的事件:

$('#checkboxTest').change(function() {
if($(this).is(':checked'))
{
$('.alertWrapper').css('background-color', 'blue');
} else {
// Your code here will fired when the checkbox is unchecked
}
}).change(); // <-- Trigger the change event on page load

关于javascript - 选中复选框时如何更改 DIV 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22657074/

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