JS添加删除DOM节点

阅读:15812次   时间:2009-10-28 21:06:25   字体:[ ]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Add&DeleteNodetitle>
<script language="javascript">
var i=1;
function insertStr() {
i++;
var td = document.createElement_x("td"); 
var tr = document.createElement_x("tr");
var tbody = document.createElement_x("tbody");
tr.appendChild(td);
tbody.appendChild(tr);
var parNode = document.getElementById("table1");
parNode.appendChild(tbody);
tr.setAttribute("name","tr"+i);
tr.setAttribute("id","tr"+i);
td.innerHTML="<input type='text' name='Tag"+i+"' id='Tag"+i+"' value='Tag"+i+"'>
<input type='button' value='Delete' name='Delete"+i+"' id='Delete"+i+"'
onClick='javascript:DeleteNode("+i+")'>";
document.form1.total.value=i;
}
//JS 删除节点
 function DeleteNode(j) 

var trnode=document.getElementById("tr"+j); 
trnode.parentNode.removeChild(trnode); 

<script> 
<head> 
<body> 
<form name="form1" method="post" action=""> 
<input name="tag1" type="text" id="tag1" value="Tag1"> 
<input name="insert" type="button" id="insert" value="Add a Tag" onClick="insertStr()"> 
<input type="hidden" name="total" id="total"> 
<form> 
<table width="400" border="1" cellspacing="0" cellpadding="0" id="table1"> 
<table> 
<body> 
<html>
 相关阅读
关于本站 - 广告服务 - 会员指南 - 联系方法
Copyright ©2003-2017 源码天空 All Rights Reserved