Change label when checkbox is checked

后端 未结 3 1852
说谎
说谎 2021-01-28 23:47

I have a lot of listst with checkboxes like so:

3条回答
  •  悲&欢浪女
    2021-01-29 00:26

    HTML:

    JavaScript:

    $( '.checkboxlist' ).on( 'click', 'input:checkbox', function () {
       $( this ).parent().toggleClass( 'highlight', this.checked );
    });
    

    Live demo: http://jsfiddle.net/MGVHX/1/

    Notice that I use event delegation, instead of binding the same handler to every check-box.

提交回复
热议问题