如何用JavaScript操作table中tr中td的值?
如何用JavaScript操作table中tr中td的值?
如何用JavaScript操作table中tr中td的值?
<html>
<head>
<title>
修改td中的值
</title>
</head>
<body>
<table id="myTable" width="400px" border="1px solid #CCC">
<tr>
<td height="50px" width="25%">
1,1</td>
<td height="50px" width="25%">
1,2</td>
<td height="50px" width="25%">
1,3</td>
<td height="50px" width="25%">
1,4</td>
</tr>
<tr>
<td height="50px" width="25%">
2,1</td>
<td height="50px" width="25%">
2,2</td>
<td height="50px" width="25%">
2,3</td>
<td height="50px" width="25%">
2,4</td>
</tr>
<tr>
<td height="50px" width="25%">
3,1</td>
<td height="50px" width="25%">
3,2</td>
<td height="50px" width="25%">
3,3</td>
<td height="50px" width="25%">
3,4</td>
</tr>
</table>
<br>
<hr>
<br>
<input type="text" size="20" id="inputText">
<input type="button" value="修改(3,3)td中的值" onclick="updateValue('inputText',2,2);"
</body>
<script>
function updateValue(textId,row,col){
table = document.getElementById('myTable');
table.rows[row].cells[col].firstChild.nodeValue = document.getElementById(textId).value;
}
</script>
</html>