有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Spring中datathtext和th:text有什么区别

我是春天新来的百里香,我无法理解这两个data-th-textth:text之间的区别

有人能用例子解释一下区别吗?我应该在什么时候使用data-th-textth:text


共 (1) 个答案

  1. # 1 楼答案

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

    Non-standard attributes we are using in the th:* form are not allowed by the HTML5 specification. To make your templates HTML5-valid use data- prefix for attribute names and hyphen (-) separators instead of 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>