0

我需要在表格的第 5 列中获取文本框的值,并在警报中显示该值。

文本框的名称为: T[1] , T[2] , T[3] ..........T[30]

 $('#MyTable tr td:nth-child(5)').each(function(index) {

       var TextBoxValue = $("input[type=text][name^=T]").eq(index).val();

    });

我的桌子有:10colums 和 30rows

但它跳过一行,并在警报框中显示奇数行文本框值。

请帮忙

4

1 回答 1

2

不完全确定您的标记是什么样子或您将.eq(index)作品放在哪里,但试试这个:

 $('#MyTable tr td:nth-child(5)').each(function(index) {

    var TextBoxValue = $("input[type=text][name^=T]", this).val();

    console.log(TextBoxValue);
});

我所做的最重要的更改是为选择器“ , this”添加了上下文。我还删除了“ .eq(index)”部分。

在这里演示:http: //jsfiddle.net/aymansafadi/CpNZV/

于 2012-05-15T18:43:05.887 回答