美文网首页程序员Spring Boot
Thymleaf里面如何使用onclick事件

Thymleaf里面如何使用onclick事件

作者: OnyWang | 来源:发表于2017-12-20 08:48 被阅读2412次

不得不说springboot+Thymleaf是一个超级开发神器。再加上mybatis自动生成,一般的小项目分分钟搞定的节奏。

问题描述

不过,最近遇到一个问题,问题如下:
在Thymleaf下面如何触发js的点击事件?一通百度之后,得到如下解决方案:

<span th:text="${classType.classname} th:onclick="'javascript:test(\''+${classType.id}+'\')'"></span>

使用th:onclick标签,最终调取如下js函数:

<script type="text/javascript">
    function test(aaa) {
        window.location.href = "alllist?classid="+aaa;
    }
</script>

以上js正常写即可。

注意事项

  1. th:onclick之后一定要记得加javascript:,否则不会生效
  2. javascript开头的要用''包括起来。

相关文章

网友评论

    本文标题:Thymleaf里面如何使用onclick事件

    本文链接:https://www.haomeiwen.com/subject/njvwwxtx.html