Javascript动态添加多行
来源:互联网 发布:oracle查询去重复数据 编辑:程序博客网 时间:2024/06/05 01:02
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GBK">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<script type="text/javascript">
//删除表格数据
function delTable(){
var theTable = document.getElementById("tblZhouqi");
while(theTable.hasChildNodes()){
theTable.removeChild(theTable.lastChild);
}
}
//添加数据
function addToTable(){
var lenZhouqi = document.getElementById("txtZhouqi").value;
var theTable = document.getElementById("tblZhouqi");
//清理数据
delTable();
for(var i=1,len=lenZhouqi;i<=len;i++){
var theRow = theTable.insertRow();
//第一列
var theCell = theRow.insertCell();
theCell.style.backgroundColor = "#cccccc";
theCell.innerText = "第" + i + "号";
theCell.value = i;
//第二列 这里可以if(i == 1){theCell.innerText =""}
//else if(i == 2){theCell.innerText =""} 或者想其他办法进行赋值,比如调用一个函数 getValue(i) ,函数里根据i返回值
theCell = theRow.insertCell();
theCell.style.backgroundColor = "#cccccc";
theCell.innerText = "小明";
theCell.value = "小明";
//第三列
theCell = theRow.insertCell();
theCell.style.backgroundColor = "#cccccc";
theCell.innerText = "20";
theCell.value = "20";
// alert("22222");
}
}
</script>
<p>行数:
<input id="txtZhouqi" name="txtZhouqi" type="text">
<input id="btnAdd" name="btnAdd" value="增加" type="button" onClick="addToTable()">
</p>
<br />
<table id="tblZhouqiHeader" name="tblZhouqi" width="85%" border="0" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#aaaaaa">序号</td>
<td bgcolor="#aaaaaa">名字</td>
<td bgcolor="#aaaaaa">年龄</td>
</tr>
</table>
<table id="tblZhouqi" name="tblZhouqi" width="85%" border="0" cellpadding="0" cellspacing="2" style="padding-top:0px;margin-top:0px;">
</table>
</body>
</html>
- Javascript动态添加多行
- javascript动态添加行
- JavaScript 动态添加行
- javascript 动态添加表格行
- javascript 动态添加表格行
- javascript 动态添加表格行
- javascript 动态添加表格行
- javascript动态添加表格行
- 动态添加行的javascript
- javascript 动态添加表格行
- javascript 动态添加表格行
- javascript 动态添加表格行
- javascript 动态添加表格行
- javascript 动态添加表格行
- javascript 动态添加表格行
- JavaScript动态添加表格行
- javascript 动态添加表格行
- javascript 动态添加表格行
- 2008.10.22 多云,薄雾,傍晚有雨
- vs.net内置Visio的UML演示:汽车租赁机构软件系统实例
- 常见排序算法的稳定性
- ASP.NET学习笔记(20081023)----给Reportviewer的ToolBar上加上打印按钮
- 如何查看客户端的IP地址,机器名,MAC地址,登陆名等信息
- Javascript动态添加多行
- 汉字编码问题
- java正则表达式
- Lisp snippets
- JAVA 上传文件的类
- 金融危机对中国IT产业四大深层影响
- 看板补充(Kanban Replenishment)之--组织间来源类型的看板
- dos批处理命令详解
- .net中的报表,你用哪个?