<!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>
js實現多個上傳附件的file檔功能變數代碼
<style type="text/css教程"> .file { font: 10pt; color: black; } </style>
<sc ript language="網頁特效">
function addfile() {
var filediv = document.all['filediv'];
var strhtml = '<span><input type="file" > <button onclick="removefile(parentnode);" >刪除</button><br></span>';
filediv.innerhtml += strhtml;
}
function removefile(obj) {
obj.removenode(true);
}
</script>
<form enctype="multipart/form-data">
<div id="filediv"></div>
<a href="javascript:void(addfile());" class="file ">添加附件</a>
</form>//方法二 像hotmail郵箱增加附件模式動態增加上傳附件代碼
<div id="files">
<div>
<input type=button onclick="add();" value=attacthment>
<script>
var html="<input name=title type=file> <input type=button value=delete onclick="remove(this)">";
function add()
{
var o=document.all["files"];
var div=document.createelement("div");
div.innerhtml=html;
o.appendchild(div);
div.childnodes[0].click();
}
function remove(obj)
{
obj.parentelement.parentelement.removechild(obj.parentelement);
}
</script>
方法三 js動態增加刪除上傳附件代碼
<style type="text/css"> .file { font: 10pt; color: black; } </style>
<script language="javascript">
var i=0;
function addfile() {
i++;
currrow=conditiontable.insertrow();
cellc=currrow.insertcell();
cellccoNtext= '<input type="file" name="file+"+i> <button onclick="removefile();" >去除</button><br>';
cellc.innerhtml=cellccoNtext;
}
function findtd(o){
if (o.nodename=="tr"|| o.nodename=="table") return;
if(o.nodename=="td")
return (o);
else
return (o.parentelement);
}
function removefile(){
o = findtd(event.srcelement);
alert(o.parentelement.rowindex*1);
conditiontable.deleterow(o.parentelement.rowindex*1);
}
function uploadfile(){
}
</script>
<form enctype="multipart/form-data">
<a href="javascript:void(addfile());" class="file">添加附件</a> <a href="javascript:void(uploadfile());" class="file">上傳附件</a>
<div id="filediv" style='height:150px;top:150px;left:0px;overflow-x:auto;overflow-y:auto ;border-style:outset; border-width:1pt;border-color: black;' >
<table id=conditiontable border=1 >
</table>
</div>
</form>
</body>
</html>