javascript - thymeleaf 片段中的 $(document).ready 函数 - $ 未定义
问题描述
我正在尝试将带有 $(document).ready 函数的 js 文件添加到 thymeleaf 片段中,以便在包含片段时始终添加 js 文件。当我这样做时,我在浏览器中收到错误消息“Uncaught ReferenceError: $ is not defined”。
pageIncludingFragment.html
...
<div th:include="fragment :: fragment"></div>
...
片段.html
<div th:fragment="fragment">
...
<script th:src="resources/js/fragment.js"></script>
</div>
片段.js
$(document).ready(function() {
...
});
有没有办法做到这一点,或者我必须每次都直接将脚本包含在 pageIncludingFragment.html 中?
解决方案
freen-m是对的,我的 jquery 包含在片段的包含之下。
推荐阅读
- vue.js - Adding image and text to Vue Select dropdown
- c# - System.IO.IOException:'进程无法访问文件'File',因为它正被另一个进程使用。'
- javascript - React 16.4 - 手动表单输入填充以及来自 getDerivedStateFromProps 的更新?
- abap - 自定义F4的新纪录
- sqlite - 是否可以获得在颤振中为 Android 模拟器创建的 SQLite 数据库的 GUI?
- mysql - 仅从 mysql 表中选择最后一个日志,使用多列的 DISTINCT
- javascript - 使用鼠标单击按钮和使用开发工具单击有什么区别?
- swift - @propertyWrapper 段错误
- ios - Visual Studio Xamarin - 使用 web 服务构建 realease iOS 项目的问题
- java - 无法生成 jar 的 openwms 和部署