Twitter Bootstrap onclick event on buttons-radio

后端 未结 9 1687
傲寒
傲寒 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条回答
  •  旧巷少年郎
    2020-12-13 04:21

    This is a really annoying one. What I ended up using is this:

    First, create a group of simple buttons with no data-toggle attribute.

    Next, write an event handler that simulates the radio button effect by 'activating' the clicked one and 'deactivating' all other buttons. (EDIT: Integrated Nick's cleaner version from the comments.)

    $('#selector button').click(function() {
        $(this).addClass('active').siblings().removeClass('active');
    
        // TODO: insert whatever you want to do with $(this) here
    });
    

提交回复
热议问题