日期:2014-05-16 浏览次数:20433 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled1</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <script type="text/javascript"> //添加子接口 function add(){ var newSub = document.all.templete.cloneNode(true); set(newSub , document.all.subs.childNodes.length); document.all.subs.appendChild(newSub); } function set(divObj , index){ divObj.id = ''; divObj.style.display = "block"; var elements = divObj.getElementsByTagName("INPUT"); for(var i=0; i<elements.length; i++){ elements[i].name = elements[i].name.replace(/\[\d*\]/, '['+index+']'); } } function remove(delLink){ document.all.subs.removeChild(delLink.parentNode.parentNode); var subDivs = document.all.subs.childNodes; for(var i=0; i<subDivs.length; i++){ set(subDivs[i] , i); } } </script> </head> <body> <div align="center"> <input type="button" value="添加子接口" onClick="add()"/> </div> <div id="subs"> <%-- 子接口层 --%> </div> <%-- 子接口 HTML模板 开始 --%> <div id="templete" style="display:none;"> <div>子接口信息 <a href="#" onclick="remove(this)" title="删除该子接口" style="font-size:12px;">删除</a> </div> <table> <tr> <td><input type="text" name="name"/></td> </tr> </table> </div> <%-- 子接口 HTML模板 结束 --%> </body> </html>
<!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=gbk" /> <title>cloneNode()</title> <script language="javascript"> i=1; function add() { var tableObject=new Object(); var isneed=true; tableObject=document.getElementById("show"); //判断是否有必要添加新的输入行 for(var j=0;j<tableObject.all.tags("input").length;j++) { var inputs = tableObject.all.tags("input")[j]; if(inputs.type=="text" && inputs.value=="") { isneed=false; } } if(isneed) { //添加一行 var newTR=tableObject.insertRow(); var td0=newTR.insertCell(); var td1=newTR.insertCell(); var td2=newTR.insertCell(); var td3=newTR.insertCell(); td0.innerHTML=(++i)+'.'; td1.innerHTML='<input type="text" name="username"/>'; var newSelect=document.getElementById("sex").cloneNode(true); newSelect.id="sex"+i; td2.appendChild(newSelect); td3.innerHTML='<input type="text" name="age" onchange="add()"/>'; } } </script> </head> <body> <form> <table id="show" border="2" bordercolor="#000000"> <tr><th></th><th>姓名</th><th>性别</th><th>年龄</th></tr> <tr id="signTR" > <td>1.</td> <td><input type="text" name="name"/></td> <td> <select name="sex" i