2012-06-13 76 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();