获取表的所有行和列的每个元素的值

Get Value of each Element of all Row and Column of a Table

本文关键字:元素 获取      更新时间:2023-09-26

好吧,我有一个表格,其中包含不同的元素,如文本框,文本区域和复选框。

我正在使用以下代码:

$('#tablaCorrectiva tr').not(':first').each(function() {
alert($(this).children("td:nth-child(1)").val()); //Get BLANK
alert($(this).children("td:nth-child(1)")); // GET "[object Object]"
}

但我没有得到元素的值。

我尝试过:

$(this).children("td:nth-child(3)").find('.acc_correc').val()

但我被定义不清。

请帮忙

试试这个

alert($(this).children("td:nth-child(3)").find(':input').val());

使用

alert($(this).children("td:nth-child(1)").html());

而不是

alert($(this).children("td:nth-child(1)").val());

检查小提琴

试试这个鳕鱼

<table id=tablaCorrectiva >
<thead>
<tr><th>code</th></tr>
</thead>
<tbody>
<tr><td><input value="pippo"></td></tr>
<tr><td><input value="pluto"></td></tr>
<tr><td><input value="paperino"></td></tr>
</tbody>
<table>
/*Suppose the first TR is head and it is under <thead></thead>*/
$('#tablaCorrectiva > tbody > tr > td').each(function(index,value) {
alert($(value).find("textarea,input").val()); 
});