- 页面取值
<span th:text="${name}"></span>
- js取值
- 将值赋给hidden域,根据id获取
<input type="hidden" th:value="${name}" id="name"/> <!--js中根据id属性名获取--> var name=$("#name").val();
- 使用th:inline属性
<script th:inline="javascript"> var name = [[${name}]]; console.log(name); </script>
<script th:inline="javascript"> /*<![CDATA[*/ var message = [[${message}]]; console.log(message); /*]]>*/ </script>