js怎么获得表单所有tr的首个td??

JavaScript018

js怎么获得表单所有tr的首个td??,第1张

js中获取tr的首个td的方法如下:

比如有如下表格table:

<tr id="value_12">

<td>firstanme_1</td>

<td>lastname_1</td>

</tr>

<tr id="value_14">

<td>firstanme_2</td>

<td>lastname_2</td>

</tr>

用js获取的方法定义:

$('#table_id tr').each(function() {

var firstName = $("td", tr)[0].val()

var id = $(tr).attr('id').split("_")[1]

})

给tr一个id,然后获取

//XX是id,string是获得的值

var row = document.getElementById('XX')

var string = row.innerHTML