2012-06-13 29 views
0

嗨,大家好,我试图去创造工具提示每HTML table cell做你们有什么想法,我怎样才能得到td属性ID这里如何让HTML表格TD特有的属性ID与jquery

非常感谢 的jQuery代码示例

$(function() { 
    $(".test").hover(
     function() { 

         var toolTipHtml = $("#ToolTipDiv").clone(); 

      $(this).append(toolTipHtml); 
      toolTipHtml.show("slow"); 
     }, 
     function() { 
      var toolTipHtml = $(this).find(".tooltip"); 

      toolTipHtml.hide(); 
      toolTipHtml.remove(); 
     } 
    ); 

}); 

echo "<table>"; 
while($row = mysql_fetch_array($result)) 
{ 
     $id = $row['id_out_org']; 
      echo "<tr>"; 
     echo "<td>" .$row['KG']."</td>";   
     echo "<td class='test'>" .$row['B']."</td>"; 
     echo "<td >" .$row['B']."</td>"; 
     echo "<td class='test'>"; 
     echo "<div id = 'ToolTipDiv' class='tooltip' style='background-color: White; display: none; width: 20%;'>"; 

     echo "Total: $ "; echo $totalp = $total + $fuel; 

     echo "</div>"; 
     "</td>"; 


     echo "</tr>";   
    } 
    echo "</table>"; 
+0

你怎么激活在胡佛的工具提示的onclick,... –

+0

更好您在http://docs.jquery.com/Plugins/Tooltip使用下面开源插件。 它满足您的需求。 – jaym

回答

1

使用一个包罗万象的选择,然后在它们之间迭代:

$("td[id$=ToolTipDiv_]").each(function() { 
    $(this).attr('title', 'some tool tip'); 
}); 
0

要想从每一个表格单元格的HTML和ID:

$('td').each(function() { 
    var toolTipHtml = $(this).html(); // now you have the contents of the cell 
    id = $(this).attr('id'); // now you have the id 
}); 
+0

非常感谢您的帮助,当我提醒toolTipHtml其警告所有单元格我只想警告只spesific列单元格,你有任何想法我该怎么做 – user961885

+0

是的..它取决于..例如,如果你只是想第一个:'$('td:eq(0)')'或者它有一个类$('td.yourclass')'或者它有一个特定的ID $(“td [id $ = ToolTipDiv_] “)' – lucuma

+0

我只是编辑我的代码上面,你可以请看看我做错了,现在我只得到第一行作为工具提示框。我哭了:(((再次感谢很多 – user961885

0

,因为你使用的是胡佛你可以使用这样的事情

$('.tooltip').hover(function() { 
    alert(this.id); 
    // or to get the id of the row 
var toolTipHtml = $("#"+this.id).clone(); 
}); 
1

更好您在 Tooltip

使用这个开源插件这可能满足您的需要。 见的例子here

$('#table td.test').tooltip();