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

利用JS动态增加行


<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>测试</title>

		<script language="JavaScript">
var count = 0;
function addRow() {
	//添加一行 
	var newTr = testTbl.insertRow(testTbl.rows.length);
	//添加两列 
	var newTd0 = newTr.insertCell();
	var newTd1 = newTr.insertCell();
	var newTd2 = newTr.insertCell();
	//设置列内容和属性 
	newTd0.innerHTML = "<input type='checkbox'>";
	newTd1.innerText = "第" + count + "行";
	count++;
}
</script>
	</head>

	<body>
		<table id="testTbl">
		</table>
		<label>
			<input type="button" value="插入行" onclick="addRow()" />
		</label>
	</body>
</html>
?