我想插入一個屬性到html代碼中。 我試過這個,但它不工作:Thymeleaf在html代碼中插入文本?
<div id="${var}"> ... </div>
我想你明白我的意思了。屬性'var'應該是id。我沒有找到一個解決辦法...
我想插入一個屬性到html代碼中。 我試過這個,但它不工作:Thymeleaf在html代碼中插入文本?
<div id="${var}"> ... </div>
我想你明白我的意思了。屬性'var'應該是id。我沒有找到一個解決辦法...
你只需要使用th:attr
屬性。據參考文檔5.1中說明:
然後輸入日:ATTR屬性,並且它的改變是在設定的標籤的屬性的值 能力:
<form action="subscribe.html" th:attr="[email protected]{/subscribe}"> <fieldset> <input type="text" name="email" /> <input type="submit" value="Subscribe!" th:attr="value=#{subscribe.submit}"/> </fieldset> </form>
的 概念很簡單:日:ATTR簡單需要一個表達式 ,它爲一個屬性賦值。在創建了相應的 控制器和信息文件,處理該文件將 是結果:
<form action="/gtvg/subscribe"> <fieldset> <input type="text" name="email" /> <input type="submit" value="¡Suscríbe!"/> </fieldset> </form>
使用此
<div th:attr="id=${var}"> ... </div>
Thymeleaf只會評估前綴th:
屬性。這裏是被評估的屬性列表:
http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#setting-value-to-specific-attributes
在你的情況,th:id
已經內置所以你可以簡單地做<div th:id="${var}"> ... </div>
,它會工作。 th:attr
,用於定義百里香通常不支持的屬性。
您是否嘗試過工作? – cralfaro