【问题标题】:Input select2 remove selected输入 select2 删除选中
【发布时间】:2017-06-13 12:55:23
【问题描述】:

早安,

我有:

        $(document).ready(function () {
                $('select[id$="cbxLocal"]').select2({ placeholder: 'Selecione primeiro uma solicitação', allowClear: true });


                $('#cbxLocal').select2({
                    ajax: {
                        url: "../Servico/Local.ashx",
                        dataType: 'json',
                        type: 'GET',
                        data: function (term, page) {

                            return {
                                q: term,
                                idTipoLocal: idTipoLocal,
                                trazerEndereco: 1
                            };
                        },
                        results: function (bond, page) {
                            return {
                                results: bond.results
                            };
                        }
                    },
                    escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                    minimumInputLength: 3,
                    //templateResult: formatRepo, // omitted for brevity, see the source of this page
                    //templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
                });

            });
            
             function limparTodosCampos() {

            $('select[id$="cbxLocal"]').select2({ placeholder: 'Selecione', allowClear: false, data: null });

        }
<label id="divCbxLocal" class="cbxLocal">
  <span>Local</span>
  <input id="cbxLocal" name="cbxLocal" class="select2" type="text" />
</label>
 <fieldset>
    <input id="btLimpar" type="button" value="Clear" onclick="limparTodosCampos()" />
            </fieldset>

我想重置 javascript 选择的值。 当我单击“清除”按钮时,我想清除用户在组合框中选择的值(select2) 我怎样做? select2 的版本是 2。

谢谢。

【问题讨论】:

  • 包括你的 jQuery/JavaScript。

标签: javascript jquery jquery-select2


【解决方案1】:

您是否要清除输入字段的值?问题不是很清楚。如果是这样,您可以使用此代码(使用 JQuery):

$(function() {
  $('.signup-btn').click(function() {
    $('.signup input[type="text"]').val('');
  });
});

此代码示例展示了如何在单击具有“signup-btn”类的按钮时清除包含在“signup”类中的文本字段。

【讨论】:

  • 我编辑了示例以包含完整的代码示例。让我知道是否还有什么可以澄清的:)
  • 它不起作用,在使用 select2 (jquery) 的输入工作中,它像组合框一样工作。
猜你喜欢
  • 2016-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-15
  • 2017-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多