How do I turn a button group in Bootstrap into a radio-style input to my form?

后端 未结 5 2030
一向
一向 2021-02-04 11:31

I have the following HTML that creates a radio button group using Bootstrap.

5条回答
  •  执念已碎
    2021-02-04 12:14

    Here is my solution: http://jsfiddle.net/tFYV9/1/

    EDIT (Code from jsFiddle)

    HTML

    
    

    JavaScript

    // Bootstrap Hack
    var _old_toggle = $.fn.button.prototype.constructor.Constructor.prototype.toggle;
    $.fn.button.prototype.constructor.Constructor.prototype.toggle = function(){
      _old_toggle.apply(this);
      var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
      var target = $parent ? $parent.data('target') : undefined;
      var value = this.$element.attr('value');
      if(target && value){
        $('#'+target).val(value);
      }
    }
    

提交回复
热议问题