我正在使用select2用于在我的 grails 项目中设置用于标记我的应用程序支持的字段。
在 html 中我已经包含了
<link rel="stylesheet" href="${resource(dir: 'css', file: 'select2.css')}" type="text/css">
<script type="text/javascript" src="../js/select2.js"></script>
<div class="select2-container select2-container-multi populate placeholder" id="s2id_e2_2" style="width: 250px">
<select id="e2_2" name="majorSkills" multiple="multiple" style="width: 250px; display: 'Select Major Skills'; " class="populate placeholder"><option></option>
<optgroup label="Java">
<option value="j2ee">J2EE</option>
<option value="hibernate">Hibernate</option>
<option value="spring">Spring</option>
</optgroup>
<optgroup label="ERP">
<option value="sap">SAP</option>
<option value="peoplesoft">Peoplesoft</option>
</optgroup>
</select>
</div>
在我的脚本中
$(document).ready(function () {
$("#e2_2").select2({
placeholder: "Select a State"
});
});
包含 js 和 css 文件,但控制台中显示的错误是
select2.js:33 ReferenceError: Can't find variable: jQuery
TypeError: 'undefined' is not a function (evaluating '$("#e2_2").select2({
placeholder: "Select a State"
})')
有人可以帮我解决这些问题吗?
最佳答案
我首先包含了 jquery - js,然后在接下来的 l 中包含了 select2.js,这样它对我来说很有效,
感谢您的回答和建议-mkoryak
关于jquery - 类型错误 : 'undefined' for select2 in grails gsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14134210/