如何使用 jquery 在表格元素中获取“td”?

Posted

技术标签:

【中文标题】如何使用 jquery 在表格元素中获取“td”?【英文标题】:How do I get the "td" in a table element with jquery? 【发布时间】:2010-09-14 16:52:11 【问题描述】:

我需要获取表格的“td”元素。我无法将鼠标悬停或 onclick 事件添加到“td”元素,因此我需要使用 JQUERY 添加它们。

我需要 JQUERY 将鼠标悬停和 onclick 事件添加到表中的所有“td”元素。

这就是我需要的,也许有人可以帮助我吗?

【问题讨论】:

【参考方案1】:
$(function() 
    $("table#mytable td").mouseover(function() 
        //The onmouseover code
    ).click(function() 
        //The onclick code
    );
);

【讨论】:

【参考方案2】:

使用以下代码开始。它应该做你需要的。

$("td").hover(function()
   $(this).css("background","#0000ff");
,
function()
  $(this).css("background","#ffffff");
);

您可以使用this as a reference, which is where I pulled that code。

【讨论】:

以上是关于如何使用 jquery 在表格元素中获取“td”?的主要内容,如果未能解决你的问题,请参考以下文章