当我在浏览器中运行页面时,它不显示任何<select>框...详细信息,当我将类更改为class="#"时,它可以正常运行。无论如何,有可能在代码源中看到选择框。

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.3/css/bootstrap-select.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.3/js/bootstrap-select.min.js"></script>

<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.3/js/i18n/defaults-*.min.js"></script>



<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

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

</head>
<body>

<select class="selectpicker" data-live-search="true" name="cidade">

<option value="test1">Test 1</option>
<option value="test2">Test 2</option>
<option value="test3">Test 3</option>
</select>

</body>

最佳答案

我遇到了类似的问题。通过对控制器的AJAX请求,返回了带有HTML的字符串,但我无法将其附加到DOM。尽管如此,经检查它仍出现在DOM中。原来,问题出在selectpicker类。删除后,成功添加了HTML,并且该元素自然无法正常工作。
经过一番搜索,我遇到了以下解决方案:

$('.selectpicker').selectpicker('refresh')

找到它here并解释为什么会发生这种情况。
希望这可以帮助。

干杯!

关于javascript - Bootstrap Select-Selectpicker消失了,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45121378/

10-09 19:23