使用重置按钮重置下拉菜单中的Select2值 [英] Resetting Select2 value in dropdown with reset button

查看:720
本文介绍了使用重置按钮重置下拉菜单中的Select2值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将选定项目重设为预设值的最佳方法是?我正在使用 Select2 库,并且在使用普通按钮 type =reset时,下拉列表中的值不会重置。 p>

因此,当我按下我的按钮时,我希望再次显示全部。



jQuery

  $(#d)。 

html

 < select id =dname =d> 
<选项已禁用>全部< /选项>
< option value =1> 1< / option>
< option value =2> 2< / option>
< option value =3> 3< / option>
< / select>


解决方案

我会尝试这样的:

  $(function(){
$(#searchclear)。click(function(){
$ (#d)。select2('val','All');
});
});


What would be the best way to reset the selected item to default? I'm using Select2 library and when using a normal button type="reset", the value in the dropdown doesn't reset.

So when I press my button I want "All" to be shown again.

jQuery

$("#d").select2();

html

<select id="d" name="d">
  <option selected disabled>All</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

解决方案

I'd try something like this:

$(function(){
    $("#searchclear").click(function(){
        $("#d").select2('val', 'All');
    });
});

这篇关于使用重置按钮重置下拉菜单中的Select2值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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