动态添加删除控件
例一:
<!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 runat="server">
<title>无标题页</title>
<script type="text/javascript" language="JavaScript">
var i=0;
function addFile()
{
var str = '<INPUT name='+"file"+i+' id='+"file"+i+' type="file" ><INPUT type="button" id="de'+i+'" name="de'+i+'" onclick="del('+i+')" value="删除" ><br/>'
document.getElementById('c_d').insertAdjacentHTML("beforeEnd",str);
i++;
}
function del(ii)
{
document.getElementById("c_d").removeChild(window.document.getElementById("file"+ii))
document.getElementById("c_d").removeChild(window.document.getElementById("de"+ii))
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="添加新附件" onclick="addFile()" id="Button1" />
<div id="c_d">
</div>
</form>
</body>
</html>
例二:<html xmlns=" http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" language="JavaScript">
var i=0;
function addFile()
{
var str = '<INPUT name='+"file"+i+' id='+"file"+i+' type="file" ><INPUT type="button" id="de'+i+'" name="de'+i+'" onclick="del('+i+')" value="删除" ><br/>'
document.getElementById('c_d').insertAdjacentHTML("beforeEnd",str);
i++;
}
function del(ii)
{
document.getElementById("c_d").removeChild(window.document.getElementById("file"+ii))
document.getElementById("c_d").removeChild(window.document.getElementById("de"+ii))
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="添加新附件" onclick="addFile()" id="Button1" />
<div id="c_d">
</div>
</form>
</body>
</html>
<script language="javascript">
var num;
num=0;
function Add() //添加控件
{
var nRow=document.all.Table1.rows.length; //获得当前TABLE的行数
var objTheRow=document.all.Table1.insertRow(nRow);//执行添加
objTheRow.insertCell(0);//添加当前行的列
//添加一个按纽控件
objTheRow.cells(0).innerHTML="<input type='file' size='70' class='font_12' name='MailFile' id='up"+num+"'><a href='#' onClick='javascript:del("+num+");'>删除</a>";
num++;
}
function del(num1) //删除控件
{
var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;//获取当前索引
document.all.Table1.deleteRow(currRowIndex);
}
</script>
var num;
num=0;
function Add() //添加控件
{
var nRow=document.all.Table1.rows.length; //获得当前TABLE的行数
var objTheRow=document.all.Table1.insertRow(nRow);//执行添加
objTheRow.insertCell(0);//添加当前行的列
//添加一个按纽控件
objTheRow.cells(0).innerHTML="<input type='file' size='70' class='font_12' name='MailFile' id='up"+num+"'><a href='#' onClick='javascript:del("+num+");'>删除</a>";
num++;
}
function del(num1) //删除控件
{
var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;//获取当前索引
document.all.Table1.deleteRow(currRowIndex);
}
</script>