How to detect radio button deselect event?

后端 未结 9 1714
不思量自难忘°
不思量自难忘° 2020-11-29 07:47

Is there an easy way to attach a \"deselect\" event on a radio button? It seems that the change event only fires when the button is selected.

HTML

&l         


        
9条回答
  •  时光取名叫无心
    2020-11-29 08:20

    I think you need to add the change function on the input level, rather than on each radio button.

    Try this:

    $("input[name='a']").change(function() {
      $("input[name='a']").each(function(){
        if(this.checked) {
            // do something when selected
        } else {
            // do something when deselected
        }
      });   
    });​
    

提交回复
热议问题