日期:2014-05-16  浏览次数:20362 次

js动态修改、获取table单元格的内容

<table border=1 width=200 height=150 id='tab'>
<tr><td>111</td><td>111</td></tr>
<tr><td>222</td><td>222</td></tr>
<tr><td>333</td><td>333</td></tr>
<tr><td>444</td><td>444</td></tr>
</table>
<p align=center><input type='button' onclick='change()'>
<script>
function change(){
document.getElementById('tab').rows[0].childNodes[0].innerText = 'aaa';
}
</script>

--------------------------------------------

<table id="test">
<tr>
<td>hello</td>
</tr>
</table>
<script language="JavaScript">
alert(document.getElementById("test").rows[0].cells[0].innerText);?
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<table id="tb">
<tr>
<td>title</td>
<td>title1</td>
</tr>
<tr>
<td>test</td>
<td>test1</td>
</tr>
</table>
<input type="button" onClick="show(tb,result);" value="获取">
<input type="text" size=10 name="result">
<script language="javascript">
function show(tb,txt)
{
document.all.result.value=document.all.tb.rows(1).cells(1).innerHTML;
}
</script>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
</tr>
<tr>
??? <td>&nbsp;</td>
??? <td><span id="feedback_info" style="color:#FF0000"></span></td>
??? <td>&nbsp;</td>
</tr>
<tr>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
</tr>
<tr>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
</tr>
<tr>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
??? <td>&nbsp;</td>
</tr>
</table>
<script>

document.getElementById("feedback_info").innerHTML="aaaaaa";

document.all.tb.rows(0).cells(1).innerHTML="aaaaaa";
</script>
</body>
</html>

js获得<table>的单元格信息

?

1. 获取表格中的某个单元格的内容

var tid=listFrame.now.rows[1].cells[2].innerHTML;

listFrame是指某一窗口或者frame
now 是表格的id?
rows[i] 是指某一行 比如属性:length
cells[j] 是指某一个单元格 rows[i].cells[j]表示第i行第j列
innerHTML是指单元格的值

2 只刷新一次

function reurl(){
url = locat