我想在选中复选框时更改 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/