<!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=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function add(){
document.getElementById("text").value="";
document.getElementById("one").style.display="block";
}
function delet(){
document.getElementById("text").value="";
document.getElementById("one").style.display="none";}
function show(){
alert(document.getElementById("text").value);
}
</script>
</head>
<body>
<div id="one" style="display:none"><input type="text" name="text" id="text"size="10"/></div>
<input type="button" onclick="add()" value="添加文本" />
<input name="delete" type="submit" onclick="delet()" value="删除文本" />
<input name="ok" type="submit" onclick="show()" value="确定" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function add(){
document.getElementById("text").value="";
document.getElementById("one").style.display="block";
}
function delet(){
document.getElementById("text").value="";
document.getElementById("one").style.display="none";}
function show(){
alert(document.getElementById("text").value);
}
</script>
</head>
<body>
<div id="one" style="display:none"><input type="text" name="text" id="text"size="10"/></div>
<input type="button" onclick="add()" value="添加文本" />
<input name="delete" type="submit" onclick="delet()" value="删除文本" />
<input name="ok" type="submit" onclick="show()" value="确定" />
</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=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var str=0;;
var childinput =new Array(5);//定义要增加文本框的数量
function add(){
childinput[str]=document.createElement("input");
document.getElementById("one").appendChild(childinput[str]);
str=parseInt(str+1);
}
function delet(){
str--;
document.getElementById("one").removeChild(childinput[str]);
}
function show(){
var sum=childinput[0].value;
for(var i=1;i<str;i++){
sum+=childinput[i].value;
}
alert(sum);
}
</script>
</head>
<body>
<div id="one" ></div>
<input type="button" onclick="add()" value="添加文本" />
<input name="delete" type="submit" onclick="delet()" value="删除文本" />
<input name="ok" type="submit" onclick="show()" value="确定" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var test={
"str":"0",
"childbr":new Array(4),
"childinput":new Array(5),//定义要增加文本框的数量
"add":function(){
this.childbr[this.str]=document.createElement("br");
this.childinput[this.str]=document.createElement("input");
document.getElementById("one").appendChild(this.childinput[this.str]);
document.getElementById("one").appendChild(this.childbr[this.str]);
this.str=parseInt(this.str+1);
},
"delet":function(){
this.str--;
document.getElementById("one").removeChild(this.childinput[this.str]);
document.getElementById("one").removeChild(this.childbr[this.str]);
},
"show":function(){
var sum=this.childinput[0].value;
for(var i=1;i<this.str;i++){
if(isNaN(parseInt(this.childinput[i].value,10)))
sum+=this.childinput[i].value;
else
sum+=parseInt(this.childinput[i].value,10);}
alert(sum);
}
}
function addinput(){
test.add();
}
function deletinput(){
test.delet();
}
function showvalue(){
test.show();}
</script>
</head>
<body>
<div id="one" ></div>
<input type="button" onclick="addinput()" value="添加文本" />
<input name="delete" type="submit" onclick="deletinput()" value="删除文本" />
<input name="ok" type="submit" onclick="showvalue()" value="确定" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var test={
"str":"0",
"childbr":new Array(4),
"childinput1":new Array(5),
"childinp1":new Array(5),
"childinp2":new Array(5),
"childinput2":new Array(5),//定义要增加文本框的数量
"add":function(){
this.childbr[this.str]=document.createElement("br");
this.childinp1[this.str]=document.createElement("span");
this.childinp2[this.str]=document.createElement("span");
this.childinput1[this.str]=document.createElement("input");
this.childinput2[this.str]=document.createElement("input");
document.getElementById("one").appendChild(this.childinp1[this.str]);
this.childinp1[this.str].innerHTML="姓名";
document.getElementById("one").appendChild(this.childinput1[this.str]);
document.getElementById("one").appendChild(this.childinp2[this.str]);
this.childinp2[this.str].innerHTML="性别";
document.getElementById("one").appendChild(this.childinput2[this.str]);
document.getElementById("one").appendChild(this.childbr[this.str]);
this.str=parseInt(this.str+1);
},
"delet":function(){
this.str--;
document.getElementById("one").removeChild(this.childinput1[this.str]);
document.getElementById("one").removeChild(this.childinput2[this.str]);
document.getElementById("one").removeChild(this.childbr[this.str]);
document.getElementById("one").removeChild(this.childinp1[this.str]);
document.getElementById("one").removeChild(this.childinp2[this.str]);
},
"show":function(){
var sum=this.childinp1[0].innerHTML+":"+this.childinput1[0].value.toString()+" "+this.childinp2[0].innerHTML+":"+this.childinput2[0].value.toString()+"\n";
for(var i=1;i<this.str;i++){
sum=sum+this.childinp1[i].innerHTML+":"+this.childinput1[i].value.toString()+" "+this.childinp2[0].innerHTML+":"+this.childinput1[0].value.toString()+"\n";}
alert(sum);
}
}function addinput(){
test.add();
}
function deletinput(){
test.delet();
}
function showvalue(){
test.show();
}
</script>
</head>
<body>
<div id="one" ></div>
<input type="button" onclick="addinput()" value="添加文本" />
<input name="delete" type="submit" onclick="deletinput()" value="删除文本" />
<input name="ok" type="submit" onclick="showvalue()" value="确定" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<title>困惑好9的问题</title>
<style type="text/css">
body
{
font-size:12px;
}
.STYLE6 {color: #000000; font-weight: bold; }
.STYLE7 {font-style:italic; font-weight: bold; }
</style>
<script type="text/javascript" language="javascript">
//增加一个TextBox
function Add()
{
var table=document.getElementById("table");
var num=document.getElementsByName("性别").length;
if(num>=2)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="visible";
}
var tr=table.insertRow(table.rows.length-2);
var td1=tr.insertCell();
var td2=tr.insertCell();
var td3=tr.insertCell();
var td4=tr.insertCell();
//var IDVal="性别"+(num+1);
//alert(IDVal);
td1.innerText="姓名"+(num+1);
td2.innerHTML="<input type='Text' name='姓名' id='姓名"+(num+1)+"' size='18'>";
td3.innerText="*性别"+(num+1);
td4.innerHTML="<input type='Text' name='性别' id='性别1"+(num+1)+"' size='32'>";
//alert(td2.innerHTML);
}
//移去最后一个TextBox
function Remove()
{
var table=document.getElementById("table");
var num=document.getElementsByName("性别").length;
if(num<=3)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="hidden";
}
table.deleteRow(table.rows.length-3);
}
</script>
<form method="post" name="RegForm" action="target.html" >
<table id="table" width="570" border="0" cellspacing="10" align="left">
<tr>
<td width="43">姓名1</td>
<td width="126"><input name="姓名" type="text" id="姓名1" size="18" /></td>
<td width="108">*性别1 </td>
<td width="235"><input name="性别" id="性别1" type="text" size="32" /></td>
</tr>
<tr>
<td>姓名2 </td>
<td><input name="姓名" type="text" id="姓名2" size="18" /></td>
<td>*性别2 </td>
<td><input name="性别" id="性别2" type="text" size="32"/></td>
</tr>
<tr>
<td colspan="2">
<input id="btnAdd" type="button" onclick="Add()" value="增加节点" />
<input id="btnRemove" type="button" style="visibility:hidden" onclick="Remove();" value="移去节点"/> </td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="submit" name="Submit" value="提交" />
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form>