上传多个文件
<script language="javascript" type="text/javascript">
function fAddAttach(){ var gAttchHTML='<div class="qrle text2">附件:</div><div class="le"><input type="file" runat="server" name="attachfile[]" class="bot3" ></div><div class="le"><input type="button" name="Submit" value=" 删除 " class="bot2" id="btnDeleteReadAttach" /></div><span></span>'; var Attach=document.getElementById("dvReadAttach"); var spnList=Attach.getElementsByTagName("SPAN"); var spn=document.createElement("DIV"); spn.className="qrc4"; spn.innerHTML=gAttchHTML; spn.childNodes[1].childNodes[0].name="attachfile[]" + spnList.length; Attach.appendChild(spn); //增加gAttchHTML fGetObjInputById(spn,"btnDeleteReadAttach").(){fDeleteAttach(this);}; document.getElementById("aAddAttach").innerHTML="继续添加附件"; Attach.style.display=""; if(spnList.length>1){ spn.childNodes[0].innerHTML=" "; } } function fGetObjInputById(obj,id){ var inputList=obj.getElementsByTagName("INPUT"); for(var i=0;i<inputList.length;i++){ if(inputList[i].id==id){ return inputList[i]; } } return null; } function fDeleteAttach(obj){ try{ obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode); var Attach=document.getElementById("dvReadAttach"); var spnList=Attach.getElementsByTagName("SPAN"); if(spnList.length==0){ document.getElementById("aAddAttach").innerHTML="添加附件"; Attach.style.display="none"; }else{ document.getElementById("aAddAttach").innerHTML="继续添加附件"; } }catch(exp){ //fDebug("fDeleteAttach",exp.description); } } </script> <a href="javascript:fAddAttach();" id="aAddAttach">添加附件</a><div id="dvReadAttach" style="display:none"> </div> <asp:Button ID="Button1" runat="server" Text="Button" /> HttpFileCollection files = HttpContext.Current.Request.Files; for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++) { HttpPostedFile hp = (HttpPostedFile)HttpContext.Current.Request.Files[i]; } |
动态添加上传按钮,上传多个文件
最新推荐文章于 2017-11-02 19:01:35 发布