如何设置多个bootstrap selectpicker的值?

时间:2018-04-15 01:22:43

标签: javascript bootstrap-selectpicker

我正在使用此bootstrap select-picker。我查看了这个question并尝试设置我拥有的两个选择器的值。但是,它没有为任何选择选择器选择值。有人知道如何单独设置这两个选择选择器的值吗?

我有两个选择选择器如下:

<div class="form-group col-md-6 col-lg-6 col-sm-6">
     <select id="firstPicker" name="selValue" class="form-control selectpicker">
          <option selected disabled value="default">Please Select</option>
          <option value="One">One</option>
          <option value="Two">Two</option>
      </select>
</div>

<div class="form-group col-md-6 col-lg-6 col-sm-6">
     <select id="secondPicker" name="selValue" class="form-control selectpicker">
          <option selected disabled value="default">Please Select</option>
          <option value="Three">Three</option>
          <option value="Four">Four</option>
      </select>
</div>

我尝试使用以下链接问题中的代码来设置两者的值:

$('select[name=selValue]').val(One);
$(".selectpicker").selectpicker("refresh");

//not sure how I can set the value for the other one?
$('select[name=selValue]').val(Four);
$(".selectpicker").selectpicker("refresh");

1 个答案:

答案 0 :(得分:1)

试试这个:

$('#firstPicker').selectpicker('val', 'One');
//$('#firstPicker').selectpicker('refresh')

$('#secondPicker').selectpicker('val', 'Four');
//$('#secondPicker').selectpicker('refresh')