六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 109|回复: 0

无刷新上传文件

[复制链接]

升级  37.33%

30

主题

30

主题

30

主题

秀才

Rank: 2

积分
106
 楼主| 发表于 2013-2-7 19:50:51 | 显示全部楼层 |阅读模式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">     
<HTML>     
<HEAD>     
<TITLE> New Document </TITLE>     
<META NAME="Generator" CONTENT="EditPlus">     
<META NAME="Author" CONTENT="">     
<META NAME="Keywords" CONTENT="">     
<META NAME="Description" CONTENT="">     
<script type="text/javascript">     
     
/*附件添加提示*/      
  function getFirefoxTip(form)      
  {      
               var tipDiv=document.createElement("div");      
               tipDiv.style.cssText="width:100px;font:12px Arial;color:#00f;text-decoration:underline";      
               tipDiv.innerHTML="添加一个附件";      
               tipDiv.onclick=function()      
               {      
                       var i=form.getAttribute("count")||0;      
                       createInput(form,parseInt(i)+1);      
               };      
               form.appendChild(tipDiv);   
  }      
     
/*删除已经添加的附件项*/      
  function removeChild(parent,child)      
  {      
  var i=parent.getAttribute("count");      
  parent.removeChild(child);      
  i--;      
  if(i==0)      
    {      
      parent.lastChild.innerHTML="添加一个附件";      
    }      
  parent.setAttribute("count",i);      
  }      
     
  /* 添加移除项*/      
  function getRemove(form,node)      
  {      
               var span=document.createElement("span");      
               span.style.cssText="font:10px Arial;color:#00f;text-decoration:underline;";      
               span.innerHTML="移除";      
               span.onclick=function(){removeChild(form,node);}      
               return span;      
  }      
     
  /*文件选择框*/      
  function createInput(form,inputIndex)      
  {      
               var i=inputIndex||0;      
               if(i==0)      
               {      
                      getFirefoxTip(form);;      
               }      
               else      
               {            
                       var inputDiv=document.createElement("div");      
                       var input=document.createElement("input");      
                       input.setAttribute("type","file");      
                       input.setAttribute("name","file_"+i);      
                       inputDiv.appendChild(input);      
                       inputDiv.appendChild(getRemove(form,inputDiv));      
                       form.insertBefore(inputDiv,form.lastChild);      
                       form.setAttribute("count",i);      
                       form.lastChild.innerHTML="再添加一个附件";      
               }      
                     
       }      
  /*初始化*/      
  function init()      
  {      
       createInput(document.forms['uploadForm']);      
  }      
</script>     
</HEAD>     
     
<BODY >     
<form name="uploadForm" action="/upload.do" target="upload" enctype="multipart/form-data" method="post"></form>     
<iframe name="upload" style="display:none"></iframe>     
</BODY></HTML>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表