简体   繁体   English

jQuery通过索引访问“ .find”中的每个匹配元素

[英]jQuery access each matched element from '.find' by an index

Using jQuery's .find() method to return a set of elements, I am trying to access items in the returned set by their order in that set. 使用jQuery的.find()方法返回一组元素,我尝试按该集中的顺序访问返回集中的项目。

For example, a table with two rows and in each row a select box and two text input fields, accessed with the following: 例如,一个具有两行的表,每一行中都有一个选择框和两个文本输入字段,可通过以下方式访问:

$('table#tbl').find('tr.row').each(function(i)
{

});

To get the first element I would have thought I could use 为了获得第一个元素,我本以为可以使用

$('table#tbl').find('tr.row').each(function(i)
{
    alert( $(this).find(':input').get(1).val() );
});

And variations of the above, but apparently this doesn't work. 以及上述的各种变化,但显然这是行不通的。 Could anyone suggest the correct method to access item x of n elements returned? 谁能建议正确的方法来访问返回的n个元素的项x?

Edit: 编辑:

JSFiddle here: http://jsfiddle.net/Lenqt/42/ JSFiddle在这里: http : //jsfiddle.net/Lenqt/42/

alert( $(this).find(':input:eq(0)').val() );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM