js 通过td的id值 如何拿到tr的id值?(动态获取)

JavaScript06

js 通过td的id值 如何拿到tr的id值?(动态获取),第1张

错误出在document.getElementById(dd)

因为页面上id为2的出现了多个,而这样获取只会取到第一个,所以tr始终为相应的第1个.

按照你的写法,用dd来保存tr的行数比较好,即i值。

然后通过document.all.table1.rows(i).id来获取tr的id值。

给tr一个id,然后获取

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

var row = document.getElementById('XX')

var string = row.innerHTML

这是获得每个tr 中td 的内容

<script>

$('#myTableProduct tr').each(function(index,ele){

$(this).find('td').each(function(index,ele){

alert($(ele).html())

})

})

</script>

不用谢我

------君少