无刷新上传文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript">

/*附件添加提示*/
function getFirefoxTip(form)
{
var tipDiv=document.createElement("div");
tipDiv.style.cssText="width:100px;font:12px Arial;color:#00f;text-decoration:underline";
tipDiv.innerHTML="添加一个附件";
tipDiv.οnclick=function()
{
var i=form.getAttribute("count")||0;
createInput(form,parseInt(i)+1);
};
form.appendChild(tipDiv);
}

/*删除已经添加的附件项*/
function removeChild(parent,child)
{
var i=parent.getAttribute("count");
parent.removeChild(child);
i--;
if(i==0)
{
parent.lastChild.innerHTML="添加一个附件";
}
parent.setAttribute("count",i);
}

/* 添加移除项*/
function getRemove(form,node)
{
var span=document.createElement("span");
span.style.cssText="font:10px Arial;color:#00f;text-decoration:underline;";
span.innerHTML="移除";
span.οnclick=function(){removeChild(form,node);}
return span;
}

/*文件选择框*/
function createInput(form,inputIndex)
{
var i=inputIndex||0;
if(i==0)
{
getFirefoxTip(form);;
}
else
{
var inputDiv=document.createElement("div");
var input=document.createElement("input");
input.setAttribute("type","file");
input.setAttribute("name","file_"+i);
inputDiv.appendChild(input);
inputDiv.appendChild(getRemove(form,inputDiv));
form.insertBefore(inputDiv,form.lastChild);
form.setAttribute("count",i);
form.lastChild.innerHTML="再添加一个附件";
}

}
/*初始化*/
function init()
{
createInput(document.forms['uploadForm']);
}
</script>
</HEAD>

<BODY οnlοad="init()">
<form name="uploadForm" action="/upload.do" target="upload" enctype="multipart/form-data" method="post"></form>
<iframe name="upload" style="display:none"></iframe>
</BODY></HTML>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值