摸索了2个星期的玩意。
页面上原有的输入框
<script language="javascript">
var num =2;
var reg = /\d+/;
function buildFileInput(){
filediv = document.createElement("div");
filediv.id = "div_"+num;
var str = filediv.id;
labeltext = document.createTextNode("附件"+num+":");
fileinput = document.createElement("input");
fileinput.type = "file";
fileinput.name = "contractfile";
fileinput.id = "contractfile";
fileinput.size="25";
btn = document.createElement("input");
btn.type = "button";
btn.value = "删除";
btn.onclick= function(){remove(reg.exec(str));};
filediv.appendChild(labeltext);
filediv.appendChild(fileinput);
filediv.appendChild(btn);
document.all.filesinput.appendChild(filediv);
num++;
}
//初始化文件输入框列表
buildFileInput();
function remove(o){
document.getElementById("filesinput").removeChild(document.getElementById("div_"+o));
}
</script>
页面上原有的输入框
<input type="file" name="importContract" id="importContract" style="font-size:13px;" size="25" />
<button onclick="buildFileInput()" style="font-size:13px;height:20px;">添 加</button>
<div id="filesinput"></div>