【问题标题】:What's the difference between data-th-text and th:text in Spring thymeleafSpring thymeleaf 中的 data-th-text 和 th:text 有什么区别
【发布时间】:2020-05-30 06:30:16
【问题描述】:

我是春季百里香的新手,我无法区分这两个 data-th-text 和 th:text。

任何人都可以在示例的帮助下解释区别,我应该什么时候使用data-th-text 和th:text?

【问题讨论】:

标签: java spring-boot thymeleaf


【解决方案1】:

两者都做同样的事情,但根据 thymeleaf 文档:

HTML5 规范不允许我们在th:* 表单中使用的非标准属性。要使您的模板 HTML5 有效,请使用 data- 前缀作为属性名称和 hyphen (-) 分隔符,而不是 semi-colons (:)

参考:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#using-texts

这不是 HTML5 有效的:

 <p th:text="#{home.welcome}">Welcome to our grocery store!</p>

这是 HTML5 有效的:

<p data-th-text="#{home.welcome}">Welcome to our grocery store!</p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 2013-01-15
    • 1970-01-01
    • 2021-11-11
    • 2018-06-18
    • 2022-01-21
    • 2022-12-04
    相关资源
    最近更新 更多