vertically displayed jquery buttonset

后端 未结 3 1737
悲哀的现实
悲哀的现实 2021-02-19 02:16

i\'m using the jquery ui button, is it possible to display the radio button vertically?it seems to default to horizontal.

http://jqueryui.com/demos/button/#radio

3条回答
  •  北海茫月
    2021-02-19 02:39

    I wrote a short plugin that implement vertical buttonset for radio buttons and checkboxes with jquery ui.

    1. jQuery Plugin

    (function( $ ){
    //plugin buttonset vertical
    $.fn.buttonsetv = function() {
      $(':radio, :checkbox', this).wrap('
    '); $(this).buttonset(); $('label:first', this).removeClass('ui-corner-left').addClass('ui-corner-top'); $('label:last', this).removeClass('ui-corner-right').addClass('ui-corner-bottom'); var maxWidth = 0; // max witdh $('label', this).each(function(index){ var labelWidth = $(this).width(); if (labelWidth > maxWidth ) maxWidth = labelWidth ; }) $('label', this).each(function(index){ $(this).width(maxWidth); }) }; })( jQuery );

    2. Sample markup

    Radio Buttonset

    Checkbox Buttonset

    3. Plugin Usage

    $(document).ready(function(){
        //call plugin 
        $("#radio").buttonsetv();
        $("#checkbox").buttonsetv();
    });
    

    Here the plugin and example code

    I hope this can help you :)

提交回复
热议问题