jQuery Tooltip only works for first row of table

半城伤御伤魂 提交于 2019-12-23 19:30:34

问题


The jQuery tooltip works great for the first row of data in my table. After that, I only get the old school windows default tooltip in both IE and FF.

Here is the HTML that builds table data:

foreach ($displayData as $row) {
echo '<tr bgcolor="' . $bgcolor[$a] . '">';
    echo '<td><span id="fancy" title="Course Description: - '.$row["TSTRDS"].'">'.$row["TSTRTP"].'</span></td>';
    echo '<td>'.$row["TSTRLC"].'</td>';
    echo '<td>'.$row["TSADDR"].'</td>';
    echo '<td>'.$row["TSDATE"].'</td>';
    echo '<td>'.$row["TSTIME"].'</td>';
    echo '<td>'.$row["TSCOST"].'</td>';
echo '</tr>';
echo '<tr bgcolor="' . $bgcolor[$a] . '">';
    echo '<td colspan="2"></td>';
    echo '<td>'.$row["TSCITY"].','.$row["TSST"].' '.$row["TSZIP"].'</td>';
    echo '<td colspan="3"></td>';
echo '</tr>';
$a = !$a; 

}

Here is my javascript:

$(document).ready(function(){
$('#fancy').tooltip({
    track: true,
    delay: 0,
    showURL: false,
    fixPNG: true,
    showBody: " - ",
    top: -15,
    left: 5
});

});

And lastly, my CSS:

#tooltip {
position: absolute;
border: 1px solid #111;
background-color: #eee;
padding: 5px;
font-size: 14px;
width: 400px; }

Seems odd that the first row works and the rest do not. Do I need some sort of looping javascript to use the tooltip for all rows of my table? I thought that jQuery tooltip would take care of that sort of thing.


回答1:


Instead of an ID like this:

id="fancy" 

You should use a class like this:

class="fancy" 

then bind it using a .class selector, like this:

$('.fancy').tooltip({

IDs are supposed to be unique in a document...when you break this rule, things start to get scary :) Use a class in situations like this one.



来源:https://stackoverflow.com/questions/3497930/jquery-tooltip-only-works-for-first-row-of-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!