How to reset value of Bootstrap-select after button click

纵然是瞬间 提交于 2019-11-27 14:27:03

问题


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

<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");

回答1:


Without "option:selected"

$("#dataPicker").val('default');
$("#dataPicker").selectpicker("refresh");



回答2:


You can write it in one single line reduces extra piece of code.

$("#dataPicker").val('default').selectpicker("refresh");


来源:https://stackoverflow.com/questions/41883537/how-to-reset-value-of-bootstrap-select-after-button-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!