Change/Get check state of CheckBox

前端 未结 11 939
别跟我提以往
别跟我提以往 2020-12-03 02:30

I just want to get/change value of CheckBox with JavaScript. Not that I cannot use jQuery for this. I\'ve tried something like this but it won\'t work.

JavaScript fu

11条回答
  •  庸人自扰
    2020-12-03 03:04

    Here is a quick implementation with samples:

    Checkbox to check all items:

    
    

    Single item (for table row):

    
    

    Js code for jQuery:

    $(document).on('click', '#btnSelectAll', function(state) {
        if ($('#btnSelectAll').is(':checked')) {
            $('.single-item').prop('checked', true);
            $('.batch-erase').addClass('d-block');
        } else {
            $('.single-item').prop('checked', false);
            $('.batch-erase').removeClass('d-block');
        }
    });
    

    Batch delete item:

    
    

提交回复
热议问题