动态添加文件File
<div id="fileBlock"></div>
<button onClick="return addFile()">添加文件</button>
<script>
var i = 1;
function addFile()
{
var dv = document.getElementById("fileBlock");
var file = document.createElement("input");
file.type = "file";
file.width="300";
file.id = file.name = "file" + i;
file.name = "title"+i;
dv.appendChild(file);
var btn = document.createElement("input");
btn.type = "button";
btn.id = btn.name = "btn" + i;
btn.value = "删除";
btn.onclick = function() {
var b = document.getElementById(btn.id);
dv.removeChild(b.nextSibling); //remove <BR>
dv.removeChild(b.previousSibling); //file
dv.removeChild(b); //btn
}
dv.appendChild(btn);
dv.appendChild(document.createElement("BR"));
i++;
return false;
}
</script>
<button onClick="return addFile()">添加文件</button>
<script>
var i = 1;
function addFile()
{
var dv = document.getElementById("fileBlock");
var file = document.createElement("input");
file.type = "file";
file.width="300";
file.id = file.name = "file" + i;
file.name = "title"+i;
dv.appendChild(file);
var btn = document.createElement("input");
btn.type = "button";
btn.id = btn.name = "btn" + i;
btn.value = "删除";
btn.onclick = function() {
var b = document.getElementById(btn.id);
dv.removeChild(b.nextSibling); //remove <BR>
dv.removeChild(b.previousSibling); //file
dv.removeChild(b); //btn
}
dv.appendChild(btn);
dv.appendChild(document.createElement("BR"));
i++;
return false;
}
</script>