我在HTML页面中使用JQuery QueryBuilder。我跟着installation guide。我的HTML头包含以下内容
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/jquery-extendext/jQuery.extendext.js"></script>
<link href="bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="bower_components/jQuery-QueryBuilder/dist/css/query-builder.default.css" rel="stylesheet" type="text/css" />
<script src="bower_components/jQuery-QueryBuilder/dist/js/query-builder.standalone.js"></script>
我的身体
<div id="builder"></div>
但是当我使用
时<script>
$('#builder').queryBuilder({
filters: [ ... ]
});
</script>
我的Chrome控制台说
query-builder.standalone.js:437 Uncaught TypeError: Cannot set property 'queryBuilder' of undefined
我的所有凉亭组件都已正确安装。
我做错了什么?
答案 0 :(得分:4)
将脚本移至构建器div 元素
下方<div id="builder"></div>
<script>
$('#builder').queryBuilder({
filters: [{id:1}] // You need to implement this
});
</script>
或使用Jquery document.ready
$(document).ready(function(){
$('#builder').queryBuilder({
filters: [{id:1}] // You need to implement this
});
})