简体   繁体   English

在html表格单元格内将mysql数据显示为工具提示<td>

[英]show mysql data as tooltip inside html table cell <td>

Hi guys im trying to populate mysql row as a tooltip with mouseover however i just only populate first row as a tool tip do you have any idea what im missing thanks a lot for your help here is my code which is show only first row as a tooltip box. 嗨,大家好,我试图用mouseover填充mysql行作为工具提示,但是我只是将第一行填充为工具提示,您知道我错过了什么吗?非常感谢您的帮助,这是我的代码,它仅显示为第一行工具提示框。

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

                            var toolTipHtml = $("#ToolTipDiv_ +'$id'").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_"/$id/"' class='tooltip' style='background-color: White; display: none; width: 20%;'>";

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

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


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

Please change your id of <div> <div id = 'ToolTipDIv' 请更改您的<div> <div id = 'ToolTipDIv'

Id must be unique for each element That the problem in your code 每个元素的ID必须唯一。代码中的问题

Hardik is right, you're only getting the first row because each of the div's that are created in the while statement has an ID of 'ToolTipDiv' so jquery just selects the first one. Hardik是正确的,您只得到第一行,因为在while语句中创建的每个div的ID为'ToolTipDiv',因此jquery只会选择第一行。 What you might can do is give the div a second class name and select it by the class so that all of the div's can be utilized like you're wanting. 您可能会做的就是给div一个第二个类名,并按类选择它,以便可以像您想要的那样使用所有div。 I think this will work... 我认为这会起作用...

jQuery: jQuery的:

$(function() {
$(".test").hover(
function() {
    var toolTipHtml = $(this).next('.ToolTipDiv').clone();
    $(this).append(toolTipHtml);
    toolTipHtml.show("slow");
}, function() {
    var toolTipHtml = $(this).find(".tooltip");

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

PHP/HTML: PHP / HTML:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM