在百里香中使用data- *属性 [英] using data-* attribute with thymeleaf

查看:59
本文介绍了在百里香中使用data- *属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用百里香叶设置data- *属性吗?

Can I set data-* attribute with thymeleaf?

据我从百里香文档中了解到,我尝试过:

As I understood from thymeleaf documentation I tried:

<div th:data-el_id="${element.getId()}"> <!-- doesn't work -->

<div data-th-el_id="${element.getId()}"> <!-- doesn't work -->

推荐答案

是的, th:attr 可以进行救援对于您的情况,这应该可以完成工作:

For your scenario, this should do the job:

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

XML规则不允许您在标记中设置两次属性,因此在同一元素中最多只能有一个 th:attr .

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()}"> 

这篇关于在百里香中使用data- *属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆