【问题标题】:How can i reset a selectpicker after hide a modal?隐藏模式后如何重置选择器?
【发布时间】:2015-04-21 03:23:59
【问题描述】:

(对不起我的英语)

嘿,我有一个选择器:

                    +                       
                    '<select class="selectpicker" id="select_seleccionar_proyecto_id">'
                    +
                    '<option value="0">Seleccione..</option>'
                    +                           
                    '<option value="1">Tarea número 1</option>'
                    +                           
                    '<option value="2">Tarea número 2</option>'
                    +                       
                    '<option value="3">Tarea número 3</option>'
                    +
                    '<option value="4">Tarea número 4</option>'
                    +                           
                    '<option value="5">Tarea número 5</option>'
                    +                       
                    '<option value="6">Tarea número 6</option>' 
                    +                   
                    '</select>'         

这个选择框在一个模态中,当我关闭这个模态时,选择框就像上次一样,例如:我选择“tarea numero 4”,我关闭模态并打开模态,“tarea numero 4” "被选中。好吧,我有一个隐藏模式后调用的方法,当我打开时我需要“seleccionar..”,但没有任何工作..

¿jquery 中的最佳选择是什么?谢谢

HideModal: function(){
    var self = this;
    $('#modal_seleccionar_tarea_id').modal('hide');
    self.LimpiarModalTarea();
    },

LimpiarModalTarea: function(){
var self = this;

 $('#select_seleccionar_proyecto_id').val("0");},

PD : 这适用于其他模式,但使用 textarea。

【问题讨论】:

    标签: jquery twitter-bootstrap modal-dialog dropdownbox jquery-selectbox


    【解决方案1】:

    如果您使用的是引导选择

    $("selectorOfSelect").val('0').selectpicker('refresh');
    

    【讨论】:

      【解决方案2】:

      尝试更改您的 jquery 代码

      来自

      $('#select_seleccionar_proyecto_id').val("0");
      

      进入

      $("#select_seleccionar_proyecto_id")[0].selectedIndex = 0;
                     //<<--  or
      $("#select_seleccionar_proyecto_id").get(0).selectedIndex = 0;
      

      通常,通过使用$('#select_seleccionar_proyecto_id').val("0"); 也可以,在hidemodal 函数中调用LimpiarModalTarea 函数是否有效?如果没有通过发出警报来确保这些功能正常工作。

      【讨论】:

      • 感谢您的回答,但不起作用,是的,如果我在“LimpiarModalTarea”中发出警报并关闭模式,警报就会起作用..所以我知道该方法很好,因为与我之前使用的相同,但在模式中使用了文本区域。
      • 你能在小提琴上添加你的代码吗?我们很容易看到那里发生了什么。
      【解决方案3】:

      我想你正在寻找这个$("#select_seleccionar_proyecto_id").prop('selectedIndex',0);

      stackoverflowSet the selected index of a Dropdown using jQuery

      【讨论】:

      • 所选索引不应被 jQuery 对象访问。您需要添加$("#select_seleccionar_proyecto_id")[0].selectedIndex = 0; 才能访问selectedIndex 属性。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-23
      相关资源
      最近更新 更多