jQuery 单击按钮后如何重置 Bootstrap-select 的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41883537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reset value of Bootstrap-select after button click
提问by Nedim Hozi?
I am using Bootstrap-select plugin (https://silviomoreto.github.io/bootstrap-select/) for my dropdown select box. After I click a button, I want the box to refresh and the "selected" option to reset. This is the dropdown
我正在为我的下拉选择框使用 Bootstrap-select 插件(https://silviomoreto.github.io/bootstrap-select/)。单击按钮后,我希望该框刷新并重置“选定”选项。这是下拉菜单
<select id="dataPicker" class="selectpicker form-control">
<option value="default" selected="selected">Default</option>
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
And this is my attempt at it, does not work. Any ideas on how it should be?
这是我的尝试,不起作用。关于它应该如何的任何想法?
$("#dataPicker option:selected").val('default');
$("#dataPicker").selectpicker("refresh");
回答by Nedim Hozi?
Without "option:selected"
没有“选项:选择”
$("#dataPicker").val('default');
$("#dataPicker").selectpicker("refresh");
回答by fauz_sp
You can write it in one single line reduces extra piece of code.
您可以在一行中编写它以减少额外的代码。
$("#dataPicker").val('default').selectpicker("refresh");