Spring mvc - 如何使用百里香叶将多个属性分配给 html 元素



我的百里香页面上有一个选择框。我已经为它定义了一个属性,例如:

th:attr="labelId='associateTSF' + ${mViewStat.index}"

有没有办法设置多个?像这样:

th:attr="labelId='associateTSF' + ${mViewStat.index}; missionGroup=${mView.missionGroup}"

我已经尝试过这个;和空白,没有成功。我找到的所有示例都具有单个值。

谢谢!

找到了!它有效。它应该用逗号分隔。

HTML 禁止重复属性,因此代码不正确。 但是,th:attr 和 data-th-attr 允许您指定几个 用逗号分隔的属性,例如:

 <a href="#"     data-th-attr="data-groupid=${somevalue},
                  data-groupname=${someothervalue}">...</a>

在这个讨论中找到了它:https://github.com/thymeleaf/thymeleaf/issues/93

这对

我有用

th:attr="attrParam1=${attrVal1}, 
         width=${width != null ? width : null}, 
         height=${height != null ? height : null}"

最新更新