Twitter Bootstrap onclick event on buttons-radio

后端 未结 9 1684
傲寒
傲寒 2020-12-13 03:51

I have a Twitter Bootstrap buttons-radio and hook an onclick event to it. But how do I check which of the buttons that got triggered?

My first thought was to simply

9条回答
  •  萌比男神i
    2020-12-13 03:57

    Looking at the example HTML for radio buttons on the Twitter Bootstrap page (http://twitter.github.com/bootstrap/base-css.html#forms), you can see that each input has a unique ID attribute, i.e. optionsRadios1 and optionsRadios2.

    The relevant HTML example snippet is included here for completeness:

    So you can use a jQuery click event, and then use the this reference to look at the id of the HTML element that was clicked.

    $('.controls').find('input').bind('click',function(event){
      if($(this).attr('id')==='optionsRadios1'){
        alert($(this).attr('id'));
      } else {
        //... call some other function
      }
    });
    

提交回复
热议问题