如何使用 JQuery 获取表的 tbody 元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6763006/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:21:53  来源:igfitidea点击:

How to get the tbody element of a table using JQuery?

jquery

提问by The Light

I have a table structure (Table1) with thead and tbody.

我有一个带有thead 和tbody 的表结构(Table1)。

My main thead also has a table inside with its own thead and tbody.

我的主要 thead 里面也有一张桌子,里面有自己的 thead 和 tbody。

When I use $('#Table1 tbody')it returns all tbody elements whereas I'd only need the tbody of the Table1.

当我使用$('#Table1 tbody')它时,它会返回所有 tbody 元素,而我只需要 Table1 的 tbody。

How could this be achieved?

这怎么可能实现?

Thanks,

谢谢,

回答by James Montagne

 $('#Table1 > tbody')

>will get direct children.

>将得到直接的孩子。

回答by Chandu

Alternative:

选择:

 $('#Table1').children('tbody') 

回答by Aravinth E

simple add table id and get the value example

简单添加表 id 并获取值 示例

 $('#dc-table tbody').on('keyup','.qty_approved', function(){
   alert('tested...');   
 });