使用javascript进行操作
<html>
<head>
<script type = 'text/javascript'>
var curRow; //全局行号
var curRowId; //选中行的记录信息的ID
var curColor;
function selectRow(tr){
if(curRow){
curRow.bgColor = curColor;
curColor = tr.bgColor;
tr.bgColor = "#FFE9B3";
}else{
curColor = tr.bgColor;
tr.bgColor = "FFE9B3";
}
curRow = tr;
curRowId = tr.id;
alert(tr.cells[0].innerText);
}
</script>
</head>
<body onload = "javascript:selectRow(1)">
<table border = "1 solid">
<tr onclick = "selectRow(this);">
<td>001</td>
<td>google</td>
</tr>
<tr onclick = "selectRow(this);">
<td>002</td>
<td>baidu</td>
</tr>
</table>
</body>
</html>
本文介绍如何使用JavaScript选择并操作HTML表格中的行,包括选择行、改变背景颜色等基本操作。
7514

被折叠的 条评论
为什么被折叠?



