如何将选择标签选项更改为按钮组? [英] How can i change select tag option into button group?

查看:125
本文介绍了如何将选择标签选项更改为按钮组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="form-group">
         <label>Select Duration</label>
           <select name="plan_duration" id="plan_duration" class="selectpicker show-tick form-control" data-live-search="true" style="width:100%;">

            </select>
 </div>

相关脚本

$("#plan_name").change(function()
{
       $.getJSON("getduration.php?city="+ $(this).val(), success = function(data)
       {
       var options = "";
       for(var i = (0); i < data.length; i++)
           {
             options += "<option>" + data[i] + "</option>";

           }
       $("#plan_duration").html("");
       $("#plan_duration").append('<option>-Select Duration-</option>');
       $("#plan_duration").append(options);
       $("#plan_duration").selectpicker('refresh');
       console.log(options);    
       });
});

推荐答案

引导程序中的按钮组是一种连续显示按钮的方法.在jQuery中,遍历所有选项,并为每个选项将一个button元素插入一个按钮组.最后,神奇地删除选择标签.

Button groups in bootstrap are a way to display buttons consecutively. In jQuery, iterate over all of the options, and for each of them insert a button element into a button group. At the end, magically remove the select tag.

$("#convert").on("click", function() {
    var btnGroup = "<div class='btn-group'></div>";
    $("body").append(btnGroup);

    $("option").each(function() {
        $(".btn-group").after("<button>" + $(this).html() + "</button>");
    });

    $("#fruit-select").remove();
});

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="fruit-select">
  <option>Pineapples</option>
  <option>Mangos</option>
  <option>Watermelons</option>
</select>

<button id="convert">Convert to Button Group</button>

这篇关于如何将选择标签选项更改为按钮组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆