[英]bootstrap-select javascript instantiation does not create object
It seems that if I create the select and options fields via Javascript / jQuery, it will not create an instance of object selectpicker for the newly created object. 看来,如果我通过Javascript / jQuery创建select和options字段,它将不会为新创建的对象创建对象selectpicker的实例。 In the documentation i cannot find how to force an instanciation. 在文档中,我找不到如何强制实例化的方法。
This is what my code looks like: 这是我的代码如下所示:
$(document).ready(function() {
var content = $('<select class="selectpicker">'
+'<option>STRING</option>'
+'</select>');
content.find('.selectpicker').selectpicker();
});
This is the error I get from the browser: 这是我从浏览器中得到的错误:
TypeError: $(...).selectpicker is not a function
content.find('.selectpicker').selectpicker();
Includes are all correct, using it embedded in the normal HTML code works. includes都是正确的,使用它嵌入在普通HTML代码中即可。
Someone tumbled already over this problem? 有人已经为这个问题跌倒了吗?
make sure bootstrap-select.min.js
is added after jquery
but before your code. 确保在jquery
之后但代码之前添加bootstrap-select.min.js
。
remove the find
as content is the select
删除find
因为内容是select
var content = $('<select class="selectpicker">'
+'<option>STRING</option>'
+'</select>');
content.selectpicker();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.