0

这是我的代码,但我无法获取在 selectpicker 引导程序中选择的值。知道怎么做吗?

<select class="selectpicker form-group show-tick" id ="department"  data-live-search="true" data-width="100%" multiple title = "Select Restaurant/Store - ID" data-max-options="1">
             <?php
                    while ($rstorefrom = mysqli_fetch_array($resultstorefrom))
                    {
                        echo "<option value = " .$rstorefrom['department']. "data-tokens=" .$rstorefrom['department'].">" .$rstorefrom['department']. "</option>";

                        echo "<script>
                          $('#department').on('click',function() {
                          alert($(this).val());
                          console.log($(this).val());
                        </script>";
                    } 


              ?>
            </select> 
4

1 回答 1

0

您必须使用图书馆事件,如changed.bs.select获取更多信息;https://silviomoreto.github.io/bootstrap-select/options/

$("#department").on("changed.bs.select",function(){
  console.log($(this).val())
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/js/bootstrap-select.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/css/bootstrap-select.min.css" rel="stylesheet"/>


<select class="selectpicker form-group show-tick" id ="department"  data-live-search="true" data-width="100%" multiple title = "Select Restaurant/Store - ID" data-max-options="1">
  <option value="1">Pizza</option>
    <option value="2">More Pizza</option>
      <option value="3">Big Pizza</option>
             </select>

于 2017-05-10T09:49:13.450 回答