动态添加表单
来源:互联网 发布:自学考试网络助学 编辑:程序博客网 时间:2024/05/01 01:07
<%@ page language="java" pageEncoding="gb2312"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>test</title>
<script type="text/javascript">
function IsIE()
{
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
//IE浏览器
return true;
}else{
return false;
}
}
function IsFF()
{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
//Firefox
return true;
}else{
//如果浏览器为其他
return false;
}
}
function IsOther()
{
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
//IE浏览器
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
//Firefox
}else{
//如果浏览器为其他
return true;
}
}
return false;
}
function resetRow()
{
document.location.reload();
}
function addRow()
{
if (IsFF()==true)
{
addRowFF();
}
if (IsIE()==true)
{
addRowIE();
}
}
//FF
function addRowFF()
{
var tb = document.getElementById('tblList');
tb.appendChild(createTR());
return true;
}
//FF
function createTd(objTag, objType, objName, objClass, colNum)
{
var td = null;
td = document.createElement('td');
obj = document.createElement(objTag);
obj.type = objType;
if (colNum!=null && colNum>1)
{
td.colSpan = colNum;
}
obj.className = objClass;
obj.name = objName;
td.appendChild(obj);
return td;
}
function createTR()
{
var tr = document.createElement('tr');
var no = document.getElementById('hidTotal').value;
no++;
document.getElementById('hidTotal').value = no;
alert(document.getElementById('hidTotal').value);
tr.appendChild(createTd("input", "text", "birth_date" + no, "jiaotong2",2));
tr.appendChild(createTd("input", "text", "addr_start" + no, "jiaotong1"));
tr.appendChild(createTd("input", "text", "addr_end" + no , "jiaotong2"));
//tr.appendChild(createTd("input", "text", "bus_fees" + no , "jiaotong1"));
return tr;
}
//IE
function addRowIE()
{
var row = createTR();
document.getElementById('tagTb').appendChild(row);
//alert(document.getElementById('divBody').innerHTML);
}
</script>
</head>
<body>
总体整个表只能有一个 div
<Form name=frmMain>
<div id="divBody">
<table border="1" id="tblList">
<TBODY id="tagTb">
<tr>
<td>name</td>
<td>age</td>
<td>academic</td>
<td>nation</td>
<tr>
<tr>
<td colspan="4">
<input type='button' value='添加一行' onclick='addRow();'></input>
<input type='button' value='恢复状态' onclick='resetRow();'></input>
</td>
</tr>
</tbody>
</table>
<input type=hidden name=hidTotal id=hidTotal value=0>
</div>
</Form>
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>test</title>
<script type="text/javascript">
function IsIE()
{
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
//IE浏览器
return true;
}else{
return false;
}
}
function IsFF()
{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
//Firefox
return true;
}else{
//如果浏览器为其他
return false;
}
}
function IsOther()
{
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
//IE浏览器
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
//Firefox
}else{
//如果浏览器为其他
return true;
}
}
return false;
}
function resetRow()
{
document.location.reload();
}
function addRow()
{
if (IsFF()==true)
{
addRowFF();
}
if (IsIE()==true)
{
addRowIE();
}
}
//FF
function addRowFF()
{
var tb = document.getElementById('tblList');
tb.appendChild(createTR());
return true;
}
//FF
function createTd(objTag, objType, objName, objClass, colNum)
{
var td = null;
td = document.createElement('td');
obj = document.createElement(objTag);
obj.type = objType;
if (colNum!=null && colNum>1)
{
td.colSpan = colNum;
}
obj.className = objClass;
obj.name = objName;
td.appendChild(obj);
return td;
}
function createTR()
{
var tr = document.createElement('tr');
var no = document.getElementById('hidTotal').value;
no++;
document.getElementById('hidTotal').value = no;
alert(document.getElementById('hidTotal').value);
tr.appendChild(createTd("input", "text", "birth_date" + no, "jiaotong2",2));
tr.appendChild(createTd("input", "text", "addr_start" + no, "jiaotong1"));
tr.appendChild(createTd("input", "text", "addr_end" + no , "jiaotong2"));
//tr.appendChild(createTd("input", "text", "bus_fees" + no , "jiaotong1"));
return tr;
}
//IE
function addRowIE()
{
var row = createTR();
document.getElementById('tagTb').appendChild(row);
//alert(document.getElementById('divBody').innerHTML);
}
</script>
</head>
<body>
总体整个表只能有一个 div
<Form name=frmMain>
<div id="divBody">
<table border="1" id="tblList">
<TBODY id="tagTb">
<tr>
<td>name</td>
<td>age</td>
<td>academic</td>
<td>nation</td>
<tr>
<tr>
<td colspan="4">
<input type='button' value='添加一行' onclick='addRow();'></input>
<input type='button' value='恢复状态' onclick='resetRow();'></input>
</td>
</tr>
</tbody>
</table>
<input type=hidden name=hidTotal id=hidTotal value=0>
</div>
</Form>
</body>
</html>
- 动态添加表单
- 动态添加表单元素
- 动态添加删除表单
- 动态 添加 表单控件
- 动态添加删减表单
- jquery动态添加表单删除表单
- js动态添加删除表单
- 用js动态添加表单
- ADF实现动态添加表单
- 动态添加的表单验证
- 动态的添加、删除表单
- 动态表单添加及动态删除元素
- 动态添加表格或者表单元素
- ASP+JavaScript动态添加表单代码收藏
- js中动态添加表单/table小结
- JavaScript 动态删除/添加HTML表单元素
- Js为表单动态添加节点内容
- js 动态添加多表单控件 div
- Visual C++ ActiveX Control for hosting Office documents in Visual Basic or HTML
- 我的 blog: http://yf888.spaces.live.com
- 基于顶点纹理的无限大海水仿真
- JAVA代码收集
- pku-cs-test2006
- 动态添加表单
- Oracle 自动启动脚本的编写
- UNIX 下让 Oracle 定时执行 *.sql 文件
- Messager for grace
- 深刻理解Oracle数据库的启动和关闭
- 表单内元素联动(为动态表单做准备)
- 信息港改版体会
- 在VC中如何结束进程和启动新进程?
- Messager for haojianfeng