無刷新上傳文件


<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.onclick=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.onclick=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 onload="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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章