日期:2014-05-16  浏览次数:20443 次

js动态添加一组输入框方法三
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">  
function add()  
{  
   var i = 1 ;
option = new Array();  
proportion = new Array();  
str='<table>';  
str=str+'<tr align=center valign=middle bgcolor=#FFFFFF>';  
str=str+'<td width="100%" height="25">'
str += "<input type='text' id='id"+i+"' name='name"+i+"'>" ;
str=str+'</td>';  
str=str+'<td width="100%" height="25"></td>';  
str=str+'</tr>';
str=str+'<tr align=center valign=middle bgcolor=#FFFFFF>';  
str=str+'<td width="100%" height="25"><input type="text"></td>';  
str=str+'<td width="100%" height="25"><input type="button" name=del onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)" value="删除"></td>';  
str=str+'</tr>';
str=str+'</table>';  
window.upid.innerHTML+=str+'';  
i++ ;
document.getElementById("num").value = i + "" ;//没添加一次,将总数累加
}
  </script>
</head>
<body>
<form name="myform" onsubmit="javascript:return check()">
<table>
<tr>
<td>
<input name="Submit2" type="button" onclick="javascript:add()"
value="增加">
<input type="hidden" id="num" name="num" value="1"><!-- 记录添加次数 -->
</td>
</tr>
<tr>
<td>
<div id="upid"></div>
</td>
</tr>
</table>
</form>
</body>
</html>