<!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>
<script 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>
//方法三
<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>