设置属性值-Thymeleaf常见用法(三)
来源:互联网 发布:tp5框架架构源码下载 编辑:程序博客网 时间:2024/05/17 09:37
设置属性值
任何属性
使用 th:attrib 设置某属性的值
<form action=“ subscribe.html” th:attr=“ action=@{/subscribe}” >
结果这样:
<form action= “ /subscribe” > 赋值或者重新设置值
重新设置img标签的属性值
<img src=“ ../../images/gtvglogo.png”
th:attr=“ src=@{/images/gtvglogo.png}, title=#{logo}, alt=#{logo}” />
设定特定属性的值
使用 th:* ,其中的*是想设置到特定属性。
比如打算设置value,那么使用 th:value,设置action的值,使用th:action即可
内置很多属性,详见使用手册 5.2 章节
一次性设置多个值
使用 th:arrtib1-attrib2
th:alt-title will set alt and title .
th:lang-xmllang will set lang and xml: lang .
附加
使用 th:attrappend 后面附加 th:attrprepend 前面附加
比如添加另外一个css样式,添加到class里面。
可以使用 th:classappend and th:styleappend,前者添加一个css的样式,后者添加style内容
固定值的布尔类型
在html中,有一种标签,没有值,按照一定的方式出现,它的值 true,但是在xhtml中,它的值是它本身。比如表单中的checked属性。
<input type=“ checkbox” name=“ option2” checked /> <! - - HTML - - >
<input type=“ checkbox” name=“ option1” checked=“ checked” /> <! - - XHTML - - >
当user.active值为true的时候,checked被设置成true,否则不设置
<input type=“ checkbox” name=“ active” th:checked=“ ${user.active}” />
设置任意属性 使用默认的处理器
th:* 就算*中属性不存在于html tags中,仍然设置,例如:
<span th:whatever=“ ${user.name}” >…</span>
结果如下:
<span whatever=“ John Apricot” >…</span>
友好的支持html5标签和元素名
<table>
<tr data- th- each=“ user : ${users}” >
<td data- th- text=“ ${user.login}” >…</td>
<td data- th- text=“ ${user.name}” >…</td>
</tr>
</table>
data-{prefix}-{name}是一种标准的方式来定义h5属性,不需要使用namespace,th:
th:text= 等价于 th-text=
- 设置属性值-Thymeleaf常见用法(三)
- Thymeleaf教程 (六) 设置属性值
- Thymeleaf教程 (六) 设置属性值
- Thymeleaf设置固定值属性
- 表达式-Thymeleaf常见用法(一)
- 标准表达式-Thymeleaf常见用法(二)
- 条件表达式-Thymeleaf常见用法(五)
- 代码片段-Thymeleaf常见用法(六)
- Thymeleaf设置任意属性
- Thymeleaf设置特定属性
- thymeleaf下设置onclick属性
- 迭代循环-Thymeleaf常见用法(四)
- Thymeleaf一次性设置多个属性为相同值
- Thymeleaf 标签学习(三)
- using thymeleaf之七设置属性的值(th:attr/th:value/th:alt-title/th:attrappend/th:attrprepend/th:checked)
- Thymeleaf中用HTML5语法设置标签和属性
- 关于thymeleaf的多条件及多属性设置
- Thymeleaf教程 (七) 条件表达式用法
- IBM主机系统与和操作系统导论期末复习知识点总结
- java 数据转换
- Qt5.3移植到arm平台
- android中 utc 和 当地时间的转换
- Android weex的使用
- 设置属性值-Thymeleaf常见用法(三)
- 安装MongoDB部分记录
- css笔记
- python pymongo 经纬度坐标距离计算
- 处理Glide刷新出现闪烁
- C/C++学习(3)#pragma pack(4) vs. #pragma pack(8)
- 大数乘法
- 环信接入java后台注册IM用户
- C/C++内存管理详解