不知道是不是你要的效果
<!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>
<button onclick="fun()">插入行</button>
<table border="1" id="tab">
</table>
<script type="text/javascript">
function fun()
{
var tb = document.getElementById("tab").tBodies[0];
var row = tb.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "hello";
cell = row.insertCell(1);
var ipt = document.createElement("input");
ipt.type = "text";
cell.appendChild(ipt);
}
</script>
</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>
</head>
<body>
<button onclick="fun()">插入行</button>
<table border="1" id="tab">
</table>
<script type="text/javascript">
function fun()
{
var tb = document.getElementById("tab").tBodies[0];
var row = tb.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "hello";
cell = row.insertCell(1);
var ipt = document.createElement("input");
ipt.type = "text";
cell.appendChild(ipt);
}
</script>
</body>
</html>
谢谢
<button onclick="add_div()">插入行</button>
<div id="DivBox"></div>
<script type="text/javascript">
function add_div()
{
var ipt = document.createElement("input");
ipt.type = "text";
div.appendChild(ipt);
}
</script>
我上面写的不对,谁能帮我改一下吗
谢谢!
改成
document.getElementById("DivBox").appendChild(ipt);
是的,谢谢,另外,这样也可以实现: <TABLE border="1" id="activeTable">
</TABLE>
<button onclick="AddRecord()">Add Record</a>
<script>
function AddRecord()
{
var row = activeTable.insertRow(activeTable.rows.length);//id=recordTable
var col = row.insertCell(0);
var i = row.rowIndex;
col.innerHTML = "<input type='text' name='texRe"+ i + "' value='' >";
col = row.insertCell(1);
col.innerHTML = "<input type='checkbox' name='texObject"+ i +"' value='' >";
col = row.insertCell(2);
col.innerHTML = "<input type='button' name='texClassOne"+ i +"' value='aaa' >";
}
</script>