用javascript从最后一个单元格向前遍历表格,把所有单元格的字符拼成一个字符串
<table id="t1" width="500" border="1" cellspacing="0" cellpadding="3">
<tr>
<td>aa</td>
<td>bb</td>
</tr>
<tr>
<td>cc</td>
<td>dd</td>
</tr>
<tr>
<td>ee</td>
<td>ff</td>
</tr>
</table>
37帝国WEB开发教程原创<script>
t=document.getElementById("t1");
row_num=t.rows.length;
cell_num=t.rows[0].cells.length;
var str=new String("");
for(i=row_num-1;i>=0;i--)
{
for(j=cell_num-1;j>=0;j--)
{
str+=t.rows[i].cells[j].innerHTML;
}
}
alert(str);
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.EvenOrOddRow{
background-color: expression((this.sectionRowIndex%2)?'white':'#E0E0E0');
}
</style>
<script>
var currentActiveRow;
function changeActiveRow(obj)
{
if(currentActiveRow) currentActiveRow.style.backgroundColor="";
currentActiveRow=obj;
currentActiveRow.style.backgroundColor="Red";
alert(currentActiveRow.cells[0].innerHTML);
alert(currentActiveRow.cells[1].innerHTML);
}
</script>
</head>
<body>
<table width=100%>
<tr bgcolor=aaaaaa >
<td>Code</td><td>Name</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr>
</body>
</html>
posted on 2008-01-11 15:55
无声 阅读(2568)
评论(0) 编辑 收藏 所属分类:
职场生活