我在 /static/js/myScript.js 的 Gradle 项目中有 myScript.js。在 HTML Thymeleaf 模板中,我有
<script type="text/javascript" th:src="@{https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/js/myExternalScript.js}"></script>
...
<input id="myBtn" type="button" th:onclick="myExternalFunc();" value="Submit" />
当我运行服务器时,我得到:
无法解析为表达式:“myExternalFunc();”
当脚本内联时它工作正常,这是我不想要的。
解决办法是:
th:onclick="'myExternalFunc();'"
或
th:onclick="'javascript:myExternalFunc();'"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句