How to create a toggle button in Bootstrap

前端 未结 10 675
自闭症患者
自闭症患者 2021-01-30 00:57

I originally created a web app in HTML, CSS and JavaScript, then was asked to create it again in Bootstrap too. I\'ve done it all fine, but I had toggle buttons in the web app t

10条回答
  •  情话喂你
    2021-01-30 01:22

    I've been trying to activate 'active' class manually with javascript. It's not as usable as a complete library, but for easy cases seems to be enough:

    var button = $('#myToggleButton');
    button.on('click', function () {
      $(this).toggleClass('active');
    });
    

    If you think carefully, 'active' class is used by bootstrap when the button is being pressed, not before or after that (our case), so there's no conflict in reuse the same class.

    Try this example and tell me if it fails: http://jsbin.com/oYoSALI/1/edit?html,js,output

提交回复
热议问题