简体   繁体   中英

jquery event listener on checkbox disable

I am currently looking for an event listener for input type=checkbox that fires when disable state changes

  1. any trigger changes disable state of any checkbox on the site
  2. event listener for state change fires

I do not want to add the event to the first trigger which changes the checkbox state. It must be independent, for the trigger may change.

What I have tried so far:

$(function(){
      $('.trigger').live('click', function(){            
          $('.eventbox').attr('disabled','disabled');
      });


      $('.eventbox').live('change', function(){
          alert('state changed');
      });
 });

Unfortunately change doesn't work.

thank you for your help. jesse

can you put a trigger on the thing that does the checkbox disabling? By that I mean, if you have some button that as a side effect disables some checkboxes on click, could you tack you listener onto the click of the button?

Try this. I think you really want to track checking/unchecking of checkbox and not enabling/disabling.

$(function(){
      $('.trigger').live('click', function(){            
          $('.eventbox').removeAttr('checked');
      });


      $('.eventbox').live('change', function(){
          alert('state changed');// this will be fired only if state was checked
      });
 });

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