var nFrom =1;
var nTo = 2;
for(var i = 0;i < table.rows.length;i++)
{
table.rows[i].cells[nFrom].swapNode(table.rows[i].cells[nFrom])
}
你看行不
var nTo = 2;
for(var i = 0;i < table.rows.length;i++)
{
table.rows[i].cells[nFrom].swapNode(table.rows[i].cells[nFrom])
}
你看行不
<TR><TD>Cell 1, Row 1</TD></TR>
<TR><TD>Cell 1, Row 2</TD></TR>
<TR><TD>Cell 1, Row 3</TD></TR>
<TR><TD>Cell 1, Row 4</TD></TR>
</TABLE>
<INPUT TYPE="button" VALUE="Change Rows" onclick="oTable.moveRow(1,2)">
<TR><TD>Cell 1, Row 1</TD></TR>
<TR><TD>Cell 1, Row 2</TD></TR>
<TR><TD>Cell 1, Row 3</TD></TR>
<TR><TD>Cell 1, Row 4</TD></TR>
</TABLE>
<INPUT TYPE="button" VALUE="第二行和第四行互换" onclick="oTable.rows(1).swapNode(oTable.rows(3))">
<TR><TD style="background-color:red;color:white">Cell 1, Row 1</TD><TD>Cell 2, Row 1</TD><TD style="background-color:blue;color:white">Cell 3, Row 1</TD></TR>
<TR><TD style="background-color:red;color:white">Cell 1, Row 2</TD><TD>Cell 2, Row 2</TD><TD style="background-color:blue;color:white">Cell 3, Row 2</TD></TR>
<TR><TD style="background-color:red;color:white">Cell 1, Row 3</TD><TD>Cell 2, Row 3</TD><TD style="background-color:blue;color:white">Cell 3, Row 3</TD></TR>
<TR><TD style="background-color:red;color:white">Cell 1, Row 4</TD><TD>Cell 2, Row 4</TD><TD style="background-color:blue;color:white">Cell 3, Row 4</TD></TR>
</TABLE>
<INPUT TYPE="button" VALUE="第一列和第三列互换" onclick="swapTableCol(oTable, 0, 2)">
<SCRIPT LANGUAGE="JavaScript">
<!--
function swapTableCol(objTbl, col1, col2)
{
for (var i=0; i < objTbl.rows.length; i++)
{
objTbl.rows[i].cells[col1].swapNode(objTbl.rows[i].cells[col2])
}
}
//-->
</SCRIPT>
<TR><TD style="background-color:red;color:white">Cell 1, Row 1</TD><TD>Cell 2, Row 1</TD><TD style="background-color:blue;color:white">Cell 3, Row 1</TD></TR>
<TR><TD style="background-color:red;color:white">Cell 1, Row 2</TD><TD>Cell 2, Row 2</TD><TD style="background-color:blue;color:white">Cell 3, Row 2</TD></TR>
<TR><TD style="background-color:red;color:white">Cell 1, Row 3</TD><TD>Cell 2, Row 3</TD><TD style="background-color:blue;color:white">Cell 3, Row 3</TD></TR>
<TR><TD style="background-color:red;color:white">Cell 1, Row 4</TD><TD>Cell 2, Row 4</TD><TD style="background-color:blue;color:white">Cell 3, Row 4</TD></TR>
</TABLE>
<INPUT TYPE="button" VALUE="第一列和第三列互换" onclick="swapTableCol(oTable, 0, 2)">
<SCRIPT LANGUAGE="JavaScript">
<!--
function swapTableCol(objTbl, col1, col2)
{
for (var i=0; i < objTbl.rows.length; i++)
{
objTbl.rows[i].cells[col1].swapNode(objTbl.rows[i].cells[col2])
}
}
//-->
</SCRIPT>