Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选择输入复选框并将样式添加到其父项_Jquery_Html_Css - Fatal编程技术网

Jquery 选择输入复选框并将样式添加到其父项

Jquery 选择输入复选框并将样式添加到其父项,jquery,html,css,Jquery,Html,Css,我正在选中一个复选框并将样式添加到其父标记中。它工作得很好。我不知道的是,当它已经被选中并删除样式时,如何做相反的操作 HTML 很明显,我使用alert只是为了在单击时检查它是否处于选择状态。您可以尝试此操作(使用更改事件): 您可以尝试以下操作(使用changeevent): 您可以尝试以下操作(使用changeevent): 您可以尝试以下操作(使用changeevent): 单击后,您可以使用检查复选框是否已选中: $("input:checkbox").click(function(

我正在选中一个复选框并将样式添加到其父标记中。它工作得很好。我不知道的是,当它已经被选中并删除样式时,如何做相反的操作

HTML

很明显,我使用alert只是为了在单击时检查它是否处于选择状态。

您可以尝试此操作(使用
更改
事件):

您可以尝试以下操作(使用
change
event):

您可以尝试以下操作(使用
change
event):

您可以尝试以下操作(使用
change
event):

单击后,您可以使用检查复选框是否已选中:

$("input:checkbox").click(function() {
    if(!$(this).prop("checked"))
        alert();
    else
        $(this).parent().parent().css("background-color","yellow");
});
单击后,您可以使用检查复选框是否已选中:

$("input:checkbox").click(function() {
    if(!$(this).prop("checked"))
        alert();
    else
        $(this).parent().parent().css("background-color","yellow");
});
单击后,您可以使用检查复选框是否已选中:

$("input:checkbox").click(function() {
    if(!$(this).prop("checked"))
        alert();
    else
        $(this).parent().parent().css("background-color","yellow");
});
单击后,您可以使用检查复选框是否已选中:

$("input:checkbox").click(function() {
    if(!$(this).prop("checked"))
        alert();
    else
        $(this).parent().parent().css("background-color","yellow");
});
您可以使用以下选项:

$("input:checkbox").click(function() {
var isChecked = $(this).attr('checked')?true:false;
if(isChecked){
$(this).parent().parent().css("background-color","yellow");
}
else
     $(this).parent().parent().css("background-color","");
});
您可以使用以下选项:

$("input:checkbox").click(function() {
var isChecked = $(this).attr('checked')?true:false;
if(isChecked){
$(this).parent().parent().css("background-color","yellow");
}
else
     $(this).parent().parent().css("background-color","");
});
您可以使用以下选项:

$("input:checkbox").click(function() {
var isChecked = $(this).attr('checked')?true:false;
if(isChecked){
$(this).parent().parent().css("background-color","yellow");
}
else
     $(this).parent().parent().css("background-color","");
});
您可以使用以下选项:

$("input:checkbox").click(function() {
var isChecked = $(this).attr('checked')?true:false;
if(isChecked){
$(this).parent().parent().css("background-color","yellow");
}
else
     $(this).parent().parent().css("background-color","");
});