<html>
<head>
<title>表格行操作 </title>
</head>
<body>
<script language="javascript">
function ChangeColor(s)
{
if (s.style.color == "white")
{
s.style.color = "black";
s.style.backgroundColor = "white";
}
else
{
s.style.color = "white";
s.style.backgroundColor = "blue";
}
}
function AddRow()
{
var context=document.getElementById("PartTable");
var sHTML;
var j=context.rows.length;
context.insertRow(j);
context.rows(j).insertCell(0);
sHTML='<tr><td><input type=\"text\" size=\"10\" /></td>';
context.rows(j).cells(0).innerHTML=sHTML;
context.rows(j).cells(0).align="center";
context.rows(j).insertCell(1);
sHTML='<td><input type=\"text\" size=\"10\" /></td>';
context.rows(j).cells(1).innerHTML=sHTML;
context.rows(j).cells(1).align="center";
context.rows(j).insertCell(2);
sHTML='<td><input type=\"text\" size=\"10\"/></td>';
context.rows(j).cells(2).innerHTML=sHTML;
context.rows(j).cells(2).align="center";
context.rows(j).insertCell(3);
sHTML='<td><input type=\"text\" size=\"10\"/></td>';
context.rows(j).cells(3).innerHTML=sHTML;
context.rows(j).cells(3).align="center";
context.rows(j).insertCell(4);
sHTML='<td><input type=\"text\" size=\"10\" style=\"text-align:right\"/></td>';
context.rows(j).cells(4).innerHTML=sHTML;
context.rows(j).cells(4).align="center";
context.rows(j).insertCell(5);
sHTML='<td><input type=\"text\" size=\"10\" style=\"text-align:right\"/></td>';
context.rows(j).cells(5).innerHTML=sHTML;
context.rows(j).cells(5).align="center";
context.rows(j).insertCell(6);
sHTML='<td><input type=\"text\" size=\"10\"/></td>'
context.rows(j).cells(6).innerHTML=sHTML;
context.rows(j).cells(6).align="center";
context.rows(j).insertCell(7);
sHTML='<td width=\"20%\"><input type=\"text\" size=\"10\" style=\"width:98%\"/></td></tr>'
context.rows(j).cells(7).innerHTML=sHTML;
context.rows(j).cells(7).align="center";
}
</script>
<table border="0" width="100%" align="center">
<tr>
<td>
<span style="font-size:20pt">表格行操作</span>
</td>
</tr>
</table>
<table border="0" width="100%" align="center">
<tr>
<td>
<input type="button" value="添加行" onClick="AddRow()"/> 
</td>
</tr>
</table>
<table border="1" id="PartTable" cellpadding="0" cellspacing="0" width="100%" align="center" bordercolordark="#FFFFFF" bordercolorlight="#000000">
<tr bgcolor="#cccccc" align="center">
<td>代码</td>
<td>名称</td>
<td>型号</td>
<td>单位</td>
<td>数量</td>
<td>单价</td>
<td>日期</td>
<td>备注</td>
</tr>
<tr align="center" onClick="ChangeColor(this)">
<td><input type="text" name="EnAlias" value="ABC001" size="10"/></td>
<td><input type="text" name="Name" value="纯碱" size="10"/></td>
<td><input type="text" name="Model" value="200KG" size="10"/></td>
<td><input type="text" name="Unit" value="袋" size="10"/></td>
<td><input type="text" name="Amount" value="10.00" size="10" style="text-align:right"/></td>
<td><input type="text" name="Price" value="988.0000" size="10" style="text-align:right"/></td>
<td><input type="text" name="Date" value="2004-07-22" size="10"/></td>
<td width="20%"><input type="text" name="Memo" value="高纯度" size="10" style="width:98%"/></td>
</tr>
<tr align="center" onClick="ChangeColor(this)">
<td><input type="text" name="EnAlias" value="DDD002" size="10"/></td>
<td><input type="text" name="Name" value="工业煤" size="10"/></td>
<td><input type="text" name="Model" value="无烟" size="10"/></td>
<td><input type="text" name="Unit" value="吨" size="10"/></td>
<td><input type="text" name="Amount" value="5.40" size="10" style="text-align:right"/></td>
<td><input type="text" name="Price" value="329.0000" size="10" style="text-align:right"/></td>
<td><input type="text" name="Date" value="2004-07-23" size="10"/></td>
<td width="20%"><input type="text" name="Memo" value="" size="10" style="width:98%"/></td>
</tr>
</table>
</body>
</html>
想要给新增的行也增加一个onclick,可以做到ChangeColor