How to make a radio button look like a toggle button

前端 未结 9 1940
鱼传尺愫
鱼传尺愫 2020-12-02 05:04

I want a group of radio buttons to look like a group of toggle buttons (but still function like radio buttons). It\'s not necessary that they look exactly like toggle button

9条回答
  •  时光取名叫无心
    2020-12-02 05:36

    I know this is an old question, but since I was just looking to do this, I thought I would post what I ended up with. Because I am using Bootstrap, I went with a Bootstrap option.

    HTML

    jQuery

    $(document).ready(function () {
        $('#divType button').click(function () {
            $(this).addClass('active').siblings().removeClass('active');
            $('#<%= hidType.ClientID%>').val($(this).data('value'));
            //alert($(this).data('value'));             
        });
    });
    

    I chose to store the value in a hidden field so that it would be easy for me to get the value server-side.

提交回复
热议问题