Checkbox change event not firing

后端 未结 4 952
南旧
南旧 2020-12-29 09:48

This is my code:






        
相关标签:
4条回答
  • 2020-12-29 10:27

    Try changing

    $('a').click(function() {
          $('.chk').attr('checked', true);
    });
    

    To -

    $('a').click(function() {
          $('.chk').attr('checked', true).trigger('change');
     });
    

    That should force a trigger of the 'change' event.

    Working demo - http://jsfiddle.net/ipr101/pwmBE/

    0 讨论(0)
  • 2020-12-29 10:32

    try this.

    <div id ="chkall"> <a href="#">check all</a> <div>
    
                $('#chkall a').live("change", function() {
                $('.chk').attr('checked', true);
                });
    
    0 讨论(0)
  • 2020-12-29 10:44

    use: $('.chk').attr('checked', true).change();

    Live example: http://jsfiddle.net/NRPSA/1/

    0 讨论(0)
  • 2020-12-29 10:44

    When you change the attribute also use the following:

    $('.chk').trigger('change');
    

    Or in your code like other people have suggested:

    $('.chk').attr('checked', true).trigger('change');
    
    0 讨论(0)
提交回复
热议问题