简体   繁体   中英

jQuery clickable not checked input:checkbox? select all check boxes?

Q1: I create a "jQuery clickable" I want when click on input:checkbox in rows checked it input:checkbox (like when click on rows)

Q2: I want when click on input:checkbox(no row) in "first row(tr)" select all check boxes ?

EXAMPLE: http://jsfiddle.net/tKBJ2/3/

$('.table_show tr, .table_show tr input[type="checkbox"]').live('click',function(){
    checkBox = $(this).find("input").prop('checkbox', true);
    $id = $('input:checkbox:checked').val();
    if (checkBox.prop('checked')) {
        $(this).css('backgroundColor', "");
        checkBox.prop('checked', false);
    }
    else {
        checkBox.prop('checked', true);
        $(this).css('backgroundColor', "#ffd6c1");
    }
});

With respect

You're probably looking for this. Edit it for your needs

http://jsfiddle.net/tKBJ2/9/

$('table tr input:first').live('click',function(){
    $("input").each(function(){
        $(this).prop('checked', 'checked'); 
    });
});

UPDATE:

http://jsfiddle.net/tKBJ2/17/

$('table tr input:first').live('click',function(){
    $new_value = $(this).prop('checked');
    $("input").not(':first').each(function(a,b){
        if ($new_value == false){
            $(this).prop('checked', false);
        }
        else
        {
            $(this).prop('checked','checked');
        }
    });
});

Q1:

http://jsfiddle.net/tKBJ2/7/

Problem is that when you click the checkbox, it directly sets the checked property, and you directly set it back.

EDIT:

I changed it quite a lot more, but it works:

http://jsfiddle.net/tKBJ2/35/

Though to be honest, I'd put the header in a thead, so you don't have to make an exception for the first row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM