如何使用 jquery 在表元素中获取“td”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/160534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get the "td" in a table element with jquery?
提问by SpoiledTechie.com
I need to get the "td" element of a table. I do not have the ability to add a mouseover or onclick event to the "td" element, so I need to add them with JQUERY.
我需要获取表格的“td”元素。我无法向“td”元素添加 mouseover 或 onclick 事件,因此我需要使用 JQUERY 添加它们。
I need JQUERY to add the mouseover and onclick event to the all "td" elements in the table.
我需要 JQUERY 将 mouseover 和 onclick 事件添加到表中的所有“td”元素。
Thats what I need, maybe someone can help me out?
这就是我需要的,也许有人可以帮助我?
回答by yfeldblum
$(function() {
$("table#mytable td").mouseover(function() {
//The onmouseover code
}).click(function() {
//The onclick code
});
});
回答by mwilliams
Work off of the following code to get you started. It should do just what you need.
完成以下代码以帮助您入门。它应该做你需要的。
$("td").hover(function(){
$(this).css("background","#0000ff");
},
function(){
$(this).css("background","#ffffff");
});
You can use this as a reference, which is where I pulled that code.
您可以将其用作参考,这是我提取该代码的地方。