请各位高手帮忙! 动态生在上传附件控件问题?
本人想做一个像126哪样的附件上传,支持多个,可增减附件数目!
本人想有JS动态生成!
<body>
<form enctype ="multipart/form-data" method="post" id="form1" runat="server">
<input type ="button" value="附件" onclick ="newUpload()" style="width: 48px" /> <a href="javascript:newUpload();">添加附件</a>
<TABLE width="100%" border="0" cellpadding="0" cellspacing="1">
<TBODY id="fileList" >
<tr ><td id="filetr" ></td></tr>
<tr><td> <div id="uploadFiles" style="display:block;">
</div>
</td></tr>
<input id="File1" type="file" />
</TBODY>
</TABLE>
<input id="Submit1" type="submit" value="submit" />
</form>
</body>
js代码
// JScript 文件
// 声明一个数组保存路径
var aryPath = new Array();
var xmlhttp;
//---新建上传
function newUpload()
{
var oFileList = document.getElementById("filetr");
var fileCount = oFileList.childNodes.length + 1;
var oFileInput = newFileInput("upfile_" + fileCount);
if(selectFile(oFileInput))
{
for(var i = 0;i< aryPath.length ;i++)
if(aryPath[i] == oFileInput.value)
{
alert("附件已存在!");
return ;
}
aryPath.push(oFileInput.value);
addFile(oFileInput);
}
}
//----选择文件
function selectFile(oFileInput)
{
var oUploadFiles = document.getElementById("uploadFiles");
oUploadFiles.appendChild(oFileInput);
oFileInput.focus();
oFileInput.click();//不能这样做,可能是为了安全着想吧!
var fileValue = oFileInput.value;
if(fileValue == "")
{
oUploadFiles.removeChild(oFileInput);
return false;
}
else
return true;
}
//---新建一个文件显示列表
function addFile(oFileInput)
{
// var oFileList = document.getElementById("fileList");
//var fileIndex = oFileList.childNodes.length + 1;
// var oTR = document.createElement("TR");
var oTR = document.getElementById("filetr");
var fileIndex = oTR.childNodes.length + 1;
// var oTD1 = document.createElement("TD");
var oTD2 = document.createElement("span");
// oTR.setAttribute("id","file_" + fileIndex);
//oTR.setAttribute("bgcolor","#FFFFFF");
// oTD1.setAttribute("id","file_" + fileIndex);
// oTD1.setAttribute("bgcolor","#FFFFFF");
oTD2.setAttribute("id","file_" + fileIndex);
oTD2.setAttribute("bgcolor","#FFFFFF");
// oTD1.setAttribute("