js动态增加表格

时间:2024-11-30 12:07:01

<!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>
</head>
<body>
<style type="text/css">
<!--
td{width:300px;text-align:center;margin:0px;padding:0px}
-->
</style>
<script language="javascript" type="text/javascript">
<!--
function show(){
var num=document.getElementById("test").getElementsByTagName("input")[0].value;
var y=parseInt(num);
for(var i=0;i<y;i++){
var strS='<table cellpadding="0" cellspacing="0" border="1px solid black"><tr><td><select style="width:102px"><option>选择产品编号</option></select></td><td><input type="text" style="width:99px" /></td><td><input type="text" style="width:100px" />(数字)</td><td><input type="text" style="width:100px" /></td></tr></table>';
document.getElementById("change").innerHTML+=strS;
}
}
//-->
</script>
<div id="test">
添加产品品种数:<input type="text" name="text" value="" />
<input type="button" name="submit" value="生成输入框" onclick="show()" />
</div>
<table cellpadding="0" cellspacing="0" border="1px solid #ccc">
<tr style="background-color:#009999">
<td>产品编号</td>
<td>产品名称</td>
<td>数量</td>
<td>单价</td>
</tr>
</table>
<div id="change">
</div>
</body>
</html>