实现上传(增删)多个文件的客户端写法。

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 chenzengxi 的 blog

在页面的客户端,实现一次上传多个文件总是非常麻烦,那个讨厌的file按钮总是改不了,这也许是个比较好的办法,给大家参考。删除

<form name="form" method="post" enctype="multipart/form-data" target="editpost" id="form1">
<select class="tbgen" name="selectfile" style="width:200"></select>
<button onclick="delfiletoselect()">删除</button>
<span id="affixfile">
 <span><input style="width:10" name="affixs" type="file" onpropertychange="addfiletoselect(this)"></span>
</span>
</form>
<script language="javascript">
 function addfiletoselect(aofile){
   if ((aofile==null)||(aofile.value=="")) return;
   var loopts = form.selectfile.options;
   loopts[loopts.length] = new option(aofile.value,aofile.uniqueid);
   aofile.parentelement.style.display = "none";
   var loobj = document.createelement("span");
   loobj.innerhtml = '<input style="width:10" name="affixs" type="file" onpropertychange="addfiletoselect(this)">';
   affixfile.insertbefore(loobj);
 }
 function delfiletoselect(){
  loel = document.all(form.selectfile.value);
  if (loel!=null){
   loel = loel.parentelement;
   affixfile.removechild(loel);
  }
  var loopts = form.selectfile.options;
  if(loopts!=null&&loopts.length>0){
   losel = loopts[form.selectfile.selectedindex]
   loopts.removechild(losel);
  }
 }
</script>

本文关键:上传
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top