Jquery切换复选框

Dim*_*tri 5 jquery

所以我有一个问题.我正在尝试切换复选框以便向父级添加一些css<tr>

这就是我到目前为止所拥有的

 $('input[type=checkbox]').toggle(function(){

    $(this).parents('tr').addClass('selectCheckBox', 970);
},
function(){

    $(this).parents('tr').removeClass('selectCheckBox', 970);
});
Run Code Online (Sandbox Code Playgroud)

但是,这样做的结果是<tr>确实接收了selectCheckBox但是复选框没有被检查.所以我尝试了以下方法:

 $('input[type=checkbox]').toggle(function(){
    $(this).attr('checked',true);
    $(this).parents('tr').addClass('selectCheckBox', 970);
},
function(){
    $(this).attr('checked',false);
    $(this).parents('tr').removeClass('selectCheckBox', 970);
});
Run Code Online (Sandbox Code Playgroud)

再一次,没有运气.

我认为它与复选框ID的外观有关.

<input type="checkbox" name="select[]" id="select[]">
Run Code Online (Sandbox Code Playgroud)

然后,我尝试[]使用\\[\\]过去使用的逃避,但没有运气.

有办法进行checkbox检查吗?

Dim*_*tri 0

我想到了。我需要使用toggleClass 以及其余的jQuery UI 参数来获得所需的效果。

$('input[type=checkbox]').click(function(){
    $(this).parents('tr').toggleClass('selectCheckBox',  1000, "easeOutSine" );
});

// Here are the parameteres below
    .toggleClass( className [, switch ] [, duration ] [, easing ] [, complete ] )
Run Code Online (Sandbox Code Playgroud)