如何在表中添加工具提示到td

时间:2011-02-14 17:56:41

标签: jquery html

每当我将td悬停在table时,有人可以给我一个添加工具提示的示例。

工具提示的内容必须来自数据库记录。

示例:

如果我将名称悬停在桌面上......工具提示必须显示他/她的信息。

6 个答案:

答案 0 :(得分:36)

使用title属性:

<table>
    <tr>
        <td>
            <a href="#" title="John Smith lives in New York."> John Smith </a>
        </td>
    </tr>
</table>

现场演示: http://jsfiddle.net/GpU5f/

答案 1 :(得分:30)

如果您向<td>添加'title =“无论什么”',您将获得悬停的工具提示:

<tr><td title="whatever">hover here to see "whatever" in a tooltip</td>

标题内容的来源是一个不同的,也许更难的故事,但也许您可以安排提供单元格的innerText的程序代码对单元格的title=...执行相同的操作。

HTH

- 皮特

答案 2 :(得分:4)

<?php
    $test = "Test"
?>


<table>
    <tr>
        <td title="<?php echo $test; ?>">Hi there</td>
    </tr>
</table>

答案 3 :(得分:3)

因为最初的问题被标记为jquery并且没有一个例子提到这个(无论多么微不足道),它只是一个问题

$(tdSelector).attr('title', titleText);

答案 4 :(得分:0)

angular.js 中,它可以像这样工作: -

<table>
<tr ng-repeat="data in list">
<td  class="table-text-right tooltip-enable-mandatory" data-toggle="tooltip" data-container="#tableRoceMovement"data-original-title="{{data.value}}" title="{{data.value}}"data-placement="bottom" data-html="true" onmouseenter="tooltipEnterEvent($(this))" onmouseleave="tooltipLeaveEvent($(this))">{{data.value}}</td>
</tr>
</table>

答案 5 :(得分:0)

title属性中的内容会显示为工具提示。

<tr><td title="whatever">hover here to see "whatever" in a tooltip</td>

我正在获得工具提示,从order.productTitle的价值中获得什么。

<td title="{{order.productTitle}}">{{order.productTitle}}</td>