如何为<th>HTML中表的元素

How to give tooltip to <th> element of table in HTML

本文关键字:元素 HTML th lt gt      更新时间:2023-09-26

如何在悬停元素时为表的元素提供工具提示。

<th id="metricsHead">Grade_Desc</th>

悬停元素时,工具提示应为"等级描述">

只需设置title属性

<table>
  <th id="metricsHead" title="Grade Description">Grade_Desc</th>
</table>

如果你想动态设置

$('#metricsHead').attr('title', "Grade Description")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <th id="metricsHead" >Grade_Desc</th>
</table>

document.getElementById('metricsHead').title = 'your new title';

jquery的另一个选项是

$('#metricsHead').prop('title', 'your new title');

您可以使用jQuery设置title属性。

$("#metricsHead").attr("title", "Grade Description");