最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery: select the first five rows of a table - Stack Overflow

programmeradmin4浏览0评论

How can I quickly get a jQuery selector for the textboxes in the the first 5 rows of a table? I have a table with many rows and many textboxes; I'm just trying to select the textboxes in the first 5 rows of the table. Is there an easy way to do this?

How can I quickly get a jQuery selector for the textboxes in the the first 5 rows of a table? I have a table with many rows and many textboxes; I'm just trying to select the textboxes in the first 5 rows of the table. Is there an easy way to do this?

Share Improve this question edited Jun 23, 2010 at 16:56 Patrick McElhaney 59.3k41 gold badges137 silver badges169 bronze badges asked Aug 4, 2009 at 17:07 HcabnettekHcabnettek 12.9k38 gold badges128 silver badges192 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 14

Use lt()

$('tr:lt(5) input[type=text]') 

Note that it's lt(5), not lt(6), since the indexes are 0-based.

try:

$("#yourTable tr:lt(5) input[type=text]")

see "http://docs.jquery.com/Selectors/nthChild#index"

try width:

$("table tbody tr:nth-child(0)").html();
$("table tbody tr:nth-child(1)").html();
$("table tbody tr:nth-child(2)").html();
$("table tbody tr:nth-child(3)").html();
$("table tbody tr:nth-child(4)").html();
发布评论

评论列表(0)

  1. 暂无评论