Подтвердить что ты не робот

Вертикально отображаемый набор кнопок jquery

Я использую кнопку jquery ui, можно ли отображать радиокнопку по вертикали? Кажется, по умолчанию она горизонтальная.

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

большое спасибо

4b9b3361

Ответ 1

Я написал короткий плагин, который реализует вертикальный набор кнопок для переключателей и флажков с jquery ui.

1. Плагин jQuery

(function( $ ){
//plugin buttonset vertical
$.fn.buttonsetv = function() {
  $(':radio, :checkbox', this).wrap('<div style="margin: 1px"/>');
  $(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. Разметка образца

<h2> Radio Buttonset </h2>
<div id="radio">
  <input type="radio" id="radio1" name="radio" value="1"/><label for="radio1">Choice 1</label>
  <input type="radio" id="radio2" name="radio" value="2"/><label for="radio2">Choice 2</label>
  <input type="radio" id="radio3" name="radio" value="3"/><label for="radio3">Choice 3</label>
</div>
<h2> Checkbox Buttonset </h2>
<div id="checkbox">
  <input type="checkbox" id="check1" name="check" value="1"/><label for="check1">Choice 1</label>
  <input type="checkbox" id="check2" name="check" value="2"/><label for="check2">Choice 2</label>
  <input type="checkbox" id="check3" name="check" value="3"/><label for="check3">Choice 3</label>
</div>

3. Использование плагинов

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

Здесь приведен код плагина и примера

Я надеюсь, что это может вам помочь:)

Ответ 2

Поместите отдельные кнопки в свои собственные теги div.

Кредит leacar21 от: https://forum.jquery.com/topic/how-to-vertical-radio-button-set

<div id="someSet"> <div><input type="radio" id="button1"... ></div> <div><input type="radio" id="button2"... ></div> <div><input type="radio" id="button3"... ></div> </div>

Ответ 3

Существует не встроенный способ сделать это... пока не в любом случае. Разметка и стилизация построены вокруг горизонтального набора.