Selectpicker没有触发

时间:2015-08-31 07:04:11

标签: jquery asp.net bootstrap-select

我正在使用silviomoreto selectpicker。问题是,当我点击选择时,它没有显示项目。

Html代码:

 <select id="tick1" multiple data-live-search="true" class="form-control selectpicker show-tick" name="tick1">
                <option Value="" hidden selected="selected"></option>
                <option Value="1">One</option>
                <option Value="2">Two</option>
                <option Value="3">Three</option>
            </select>

JQuery代码:

<script type="text/javascript">
$(document).ready(function (e) {
    $(".selectpicker").selectpicker();
});
</script>

问题是,当我点击选择选择器并按 ctrl + d 时,选择器会触发,我可以使用它但是当我点击其他地方时它不会关闭。

谢谢

1 个答案:

答案 0 :(得分:1)

我多次遇到同样的问题。 将属性data-container添加到select元素应该可以解决该问题。

$("#tick1").selectpicker();
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">


<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet"/>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>


<select id="tick1" multiple data-live-search="true" data-container="body" class="form-control selectpicker show-tick" name="tick1">
  <option Value="" hidden selected="selected"></option>
  <option Value="1">One</option>
  <option Value="2">Two</option>
  <option Value="3">Three</option>
</select>