我在
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
我所有的凉亭组件都安装得当.
我究竟做错了什么?
解决方法
将脚本移动到构建器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 }); })