【发布时间】:2018-11-26 11:52:47
【问题描述】:
我想为响应式数据表添加数据标题属性。而td data-title 包含 break 语句标签。但是 break 语句标签不起作用。下面是我的示例代码,
<td data-title='Goods<br>Code'></td>
我想要两行中的“商品”和“代码”。
【问题讨论】:
-
你不能在
data-属性中使用HTML标签。
标签: html
我想为响应式数据表添加数据标题属性。而td data-title 包含 break 语句标签。但是 break 语句标签不起作用。下面是我的示例代码,
<td data-title='Goods<br>Code'></td>
我想要两行中的“商品”和“代码”。
【问题讨论】:
data-属性中使用HTML标签。
标签: html
我认为data-*属性只支持字符串,html代码不会影响它所以尝试改变
<td data-title='Goods<br>Code'></td>
到
<td data-title="Goods\nCode"></td>
\n 换行
编辑
尝试添加data-html="true"
我看到这个答案请检查一下
https://stackoverflow.com/a/13705417/5441049
或者使用JQuery工具提示插件
https://www.w3schools.com/bootstrap/bootstrap_ref_js_tooltip.asp
【讨论】:
这个应该可以:
#table th, #table td{
padding:0.8em;
border: 1px solid;
}
#table th{
background-color:#6699FF;
font-weight:bold;
}
<table id="table">
<tr>
<th>ID</th>
<th>Text</th>
</tr>
<tr>
<td>1</td>
<td title="Goods
Code">Hover Me</td>
</tr>
</table>
只需运行 sn-p 并将鼠标悬停在“悬停我”单元格上,您应该会看到您想要的标题。
"
 is \r and 
 is \n On Windows new line is 
 on unix 
"
【讨论】: