问题描述
我正在尝试使用 bootstrap-select 并从javascript中引用它,但是我总是出现错误:.selectpicker is not a function
I'm trying to use bootstrap-select and reference it from javascript, but I always get an error: .selectpicker is not a function
我所读到的有关该错误的所有信息都表明我缺少依赖项,或者在正确的时间未加载依赖项,但是我对丢失的内容一无所知.
Everything I've read about this error says I have a dependency missing or not loaded at the right time, but I'm at a loss as to what I'm missing.
此外,当我从控制台尝试$('.selectpicker').selectpicker();
时,也会遇到相同的错误,这告诉我在加载所有内容之前运行javascript并不是问题.
Also, I get the same error when I try $('.selectpicker').selectpicker();
from the console, which tells me that it's not an issue with my javascript running before everything's loaded.
这是我页面的相关部分:
Here's the relevant portions of my page:
<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/bootstrap-select.css" rel="stylesheet"/>
...
<script src="/Scripts/jquery-2.2.3.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>
<script src="/Scripts/bootstrap-select.js"></script>
...
<select class="selectpicker">
</select>
...
<script type="text/javascript">
$(document).ready(function () {
$('.selectpicker').selectpicker();
});
</script>
推荐答案
找到了它.我有第二个jquery引用,它重新加载jquery并清除了bootstrap-select.js
添加的功能.
Found it. I had a second jquery reference that was re-loading jquery and wiping out the functions added by bootstrap-select.js
.
这篇关于.selectpicker不是功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!