<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function a()
{
var rows=document.getElementById('TTT').rows.length;
for(i=0;i<rows;i++)
{
alert(alert(document.getElementById('TTT').rows[i].cells[1].innerText););
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="button" name="button" id="button" value="Button" onclick="javascript:a();"/>
</label>
<table width="98%" border="1" id="TTT">
<tr>
<td> </td>
<td>a</td>
</tr>
</table>
</form>
</body>
</html>
//////////////////////////////删除行/////////////////////////////
<script>
function del(obj)
{
obj.parentNode.parentNode.removeNode(true);
}
</script>
<body>
<table>
<tr><td>单元格1</td><td><input type=button value="delete this row" onclick="del(this)"></td></tr>
</table>
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function a()
{
var rows=document.getElementById('TTT').rows.length;
for(i=0;i<rows;i++)
{
alert(alert(document.getElementById('TTT').rows[i].cells[1].innerText););
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="button" name="button" id="button" value="Button" onclick="javascript:a();"/>
</label>
<table width="98%" border="1" id="TTT">
<tr>
<td> </td>
<td>a</td>
</tr>
</table>
</form>
</body>
</html>
//////////////////////////////删除行/////////////////////////////
<script>
function del(obj)
{
obj.parentNode.parentNode.removeNode(true);
}
</script>
<body>
<table>
<tr><td>单元格1</td><td><input type=button value="delete this row" onclick="del(this)"></td></tr>
</table>
</body>
本文介绍了一种使用HTML和JavaScript来创建及操作表格的方法。其中包括如何通过JavaScript访问表格元素并对其进行读取和删除行等操作。
768

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



