【问题标题】:how to get html table td attribute unique id with jquery如何使用 jquery 获取 html 表 td 属性的唯一 ID
【发布时间】:2012-06-13 04:16:22
【问题描述】:

大家好,我正在尝试为每个 HTML table cell 创建工具提示,你们知道我如何在此处获取 td 属性 ID

非常感谢 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>";

【问题讨论】:

  • 你是如何在 hoover、onclick 上激活工具提示的......
  • 你最好使用下面的开源插件docs.jquery.com/Plugins/Tooltip。它满足您的需求。

标签: php jquery mysql html show-hide


【解决方案1】:

使用包罗万象的选择器,然后遍历它们:

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

【讨论】:

    【解决方案2】:

    最好使用这个开源插件 Tooltip

    它可能会满足您的需求。 见例子here

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

    【讨论】:

      【解决方案3】:

      从每个表格单元格中获取 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
      });
      

      【讨论】:

      • 非常感谢您的帮助,当我提醒 toolTipHtml 它提醒所有单元格时,我只想提醒特定的列单元格,您知道我该怎么做吗
      • 是的.. 这取决于.. 例如,如果您只想要第一个:$('td:eq(0)') 或者它有一个类 $('td.yourclass') 或者它有一个特定的 id $("td[id$=ToolTipDiv_]")
      • 我只是在上面编辑了我的代码,请你看看我做错了什么,现在我只得到第一行作为工具提示框。我很想哭:(((再次非常感谢
      【解决方案4】:

      因为你使用的是胡佛,你可能会使用这样的东西

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-31
        • 1970-01-01
        • 1970-01-01
        • 2012-10-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多