Twitter Bootstrap onclick event on buttons-radio

后端 未结 9 1702
傲寒
傲寒 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:05

    I needed to do the same thing for a chart where you could select the period of the data that should be displayed.

    Therefore I introduced the CSS class 'btn-group-radio' and used the following unobtrusive javascript one-liner:

    // application.js
    $(document).ready(function() {
      $('.btn-group-radio .btn').click(function() {
        $(this).addClass('active').siblings('.btn').removeClass('active');
      });
    });
    

    And here is the HTML:

    
    
    <%= link_to '1W', charts_path('1W'), class: 'btn btn-default active', remote: true %> <%= link_to '1M', charts_path('1M'), class: 'btn btn-default', remote: true %> <%= link_to '3M', charts_path('3M'), class: 'btn btn-default', remote: true %> <%= link_to '6M', charts_path('6M'), class: 'btn btn-default', remote: true %> <%= link_to '1Y', charts_path('1Y'), class: 'btn btn-default', remote: true %> <%= link_to 'All', charts_path('all'), class: 'btn btn-default', remote: true %>

提交回复
热议问题