点滴分享

SpringBoot | 点滴分享

All posts in “SpringBoot”

thymeleaf使用附加属性data-*的方法

使用th:attr解决。

th:attr to the rescue Thymeleaf documentation – Setting attribute values.

For your scenario, this should do the job:

<div th:attr="data-el_id=${element.getId()}">

XML rules do not allow you to set an attribute twice in a tag, so you can’t have more than one th:attr in the same element.

Note: If you want more that one attribute, separate the different attributes by comma:如果想使用多个,方法如下

<div th:attr="data-id=${element.getId()},data-name=${element.getN‌​ame()}"> 

如果想拼接字符串。

If you need to include a variable as part of a string you need to do this: th:attr="data-id='some-text'+${element.getId()}+'some-other-‌​text',data-name=${el‌​ement.getName()}"


原地址:https://stackoverflow.com/questions/24411826/using-data-attribute-with-thymeleaf
2017年11月22日 0 / /
标签:  暂无标签
回到顶部