【问题标题】:create a button to delete choosen value on select2创建一个按钮以删除 select2 上的选定值
【发布时间】:2016-11-03 12:33:18
【问题描述】:

我想问一下select2。 当客户选择列表时,我有 2 个 select2。客户端选择列表后,按钮会显示值的名称选择和值转到按钮而不是输入区域 select2,因此 select2 将保留在占位符中。

<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1">
    <!-- the name of button is the value of what we choose in first select2  /example Alabama-->
    <span class="glyphicon glyphicon-remove"></span>
 </button>

按钮具有allowClear: true 之类的功能。 怎么会这样 我把它放在jsfiddle上 https://jsfiddle.net/mujkz5v3/1/

非常感谢,请帮忙

【问题讨论】:

    标签: javascript jquery jquery-select2 select2


    【解决方案1】:

    使用 $("#dropdownMenu1").html(度数);

    或 $("#dropdownMenu1").text( deggre );

    而不是 .val

    【讨论】:

      【解决方案2】:

      查看以下更改:

      $('.deggre').on('change', function() {
          var deggre = $( this ).val();
          var span = $("#dropdownMenu1").find('span').clone(); // Copy 'X' span.
          $("#dropdownMenu1").text(deggre); // Insert text first.
          $("#dropdownMenu1").append(span); // Then, append the 'X' span.
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-05
        • 2015-02-16
        • 2016-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多