当前位置: 移动技术网 > IT编程>开发语言>Java > thymeleaf添加点击事件 “th:onclick”传参使页面报错问题

thymeleaf添加点击事件 “th:onclick”传参使页面报错问题

2020年07月22日  | 移动技术网IT编程  | 我要评论

thymeleaf th:onclick传参问题解决

最近在开发过程中遇到springBoot使用thymeleaf模板引擎,添加点击事件会使页面报错的问题,下面分享一下自己的解决方法。
一:可能是版本问题,在springboot2.0.0版本中使用下面写法会报错。

<li th:each="city:${cityList}">
      <a href="#" th:onclick="getSchoolList([[${city.id}]],[[${city.cityName}]]);">[[${city.cityName}]]</a>
</li>

在pom.xml中换成2.2.6版本或更高版本后使用正常。

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.6.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

二:在不改变版本的情况下将写法换成这样,我的问题也解决了

	<li th:each="city:${cityList}" th:onclick="|getSchoolList('${city.id}','${city.cityName}');|">
            <a href="#">[[${city.cityName}]]</a>
    </li>

本文地址:https://blog.csdn.net/xl13003009535/article/details/107498985

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网