使用Javascript动态增加,删除表格
2008-02-13 13:41
691 查看
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<head>
<script language="javascript">...
function deleteRow(index)...{
var tableObj=document.getElementById("mytable");
tableObj.deleteRow(tableObj.rows.length-1);
}
function addRow()...{
var tableObj=document.getElementById("mytable");
var newRowObj=tableObj.insertRow(tableObj.rows.length);
var newColName=newRowObj.insertCell(newRowObj.cells.length);
var newColAge=newRowObj.insertCell(newRowObj.cells.length);
var newColButton=newRowObj.insertCell(newRowObj.cells.length);
newColName.innerHTML=document.getElementById("newName").value;
newColAge.innerHTML=document.getElementById("newAge").value;
newColButton.innerHTML='<input type="button" value="删除" onclick="deleteRow();">';
}
</script>
</head>
<body>
<table width="100%" id="mytable" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>姓名</td>
<td>年龄</td>
<td>操作</td>
</tr>
</table>
<input type="text" name="name" id="newName" />
<input type="text" name="age" id="newAge"/>
<input type="button" onclick="addRow();" value="新增"/>
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<head>
<script language="javascript">...
function deleteRow(index)...{
var tableObj=document.getElementById("mytable");
tableObj.deleteRow(tableObj.rows.length-1);
}
function addRow()...{
var tableObj=document.getElementById("mytable");
var newRowObj=tableObj.insertRow(tableObj.rows.length);
var newColName=newRowObj.insertCell(newRowObj.cells.length);
var newColAge=newRowObj.insertCell(newRowObj.cells.length);
var newColButton=newRowObj.insertCell(newRowObj.cells.length);
newColName.innerHTML=document.getElementById("newName").value;
newColAge.innerHTML=document.getElementById("newAge").value;
newColButton.innerHTML='<input type="button" value="删除" onclick="deleteRow();">';
}
</script>
</head>
<body>
<table width="100%" id="mytable" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>姓名</td>
<td>年龄</td>
<td>操作</td>
</tr>
</table>
<input type="text" name="name" id="newName" />
<input type="text" name="age" id="newAge"/>
<input type="button" onclick="addRow();" value="新增"/>
</body>
</html>
相关文章推荐
- 使用Javascript动态增加,删除表格(使用DHTML对象模型)
- 使用Javascript动态增加,删除表格
- 使用Javascript动态增加,删除表格(使用W3C对象模型)
- 使用JavaScript操作DOM动态增加删除表格
- 使用Javascript动态增加,删除表格(使用DHTML对象模型)
- 使用Javascript动态增加,删除表格(使用DHTML对象模型)
- 使用Javascript动态增加,删除表格(使用DHTML对象模型)
- javascript实例教程:动态增加、删除表格
- 使用JavaScript动态增加表格的行与列
- 使用JAVASCRIPT实现动态增加、删除选择项
- javascript实现动态增加删除表格行(兼容IE/FF)
- 利用javaScript动态增加表格行,删除表格行
- javascript动态增加、删除、填充表格内容
- 使用javascript操作多选列表框,实现动态增加删除,左右移动,上下排序移动等功能。
- 使用JAVASCRIPT实现动态增加、删除选择项
- 使用JavaScript动态增加表格的行与列
- javascript动态增加、删除、填充表格内容
- javascript动态增加、删除、填充表格内容
- javascript动态增加、删除、填充表格内容
- 如何使用javascript建立动态表格,有新增,删除功能