想做一个类试163邮箱的文件上传功能,上传文件无须刷新页面不用点一下提交才执行上传!!
请大虾们指点指点!

解决方案 »

  1.   

    form有个属性叫target,把target设成一个隐藏的iframe的名字,就可以提交form并且页面(form所在的页面)不刷新了
      

  2.   

    回JK_10000(JK):你的方法我用过,但是163邮箱的文件上传肯定不是用这样的方法。就是想知道163是怎么做的。
    希望有人指点。
      

  3.   

    给你段代码
    css
    ---------------------------------------
    <style>
    form{ margin:0; padding:0;}
    .fileUpArea{ width:63px; height:13px; background:url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif) no-repeat left top; overflow:hidden;}
    .fileHover{ width:63px; height:13px; background:url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif) no-repeat left top; overflow:hidden;}
    #fileUpArea input{ width:1%;size:0%; position:absolute; margin-left:-16px; z-index:100;filter:alpha(opacity=0);-moz-opacity:0;cursor:point;}
    * html #fileUpArea input{ margin-top:-5px; margin-left:-10px;}
    *+html #fileUpArea input{ margin-top:-5px; margin-left:-10px;}
    #filetxt{ font-size:12px; color:#555; padding:10px;}
    #filetxt img{ cursor:point;}
    </style>javascript
    ----------------------
    var inputCount=1;
    /*创建 input file*/
    function CreateFile()
    {
    var container=document.getElementById("fileUpArea");
    container.onmouseover=function(event)
    {
        this.className="fileHover";
    }
    container.onmouseout=function(event)
    {
        this.className="fileUpArea";
    }
    var input=document.createElement("input");
    input.type="file";
    input.size="1";

    input.name="file_"+inputCount;
    input.id="multi_file_"+inputCount;
    input.onchange=function(event)
    {
        if(CheckFileName(this.value)&&CheckFileNum(5))
        {   var textName=this.value;
         textName=textName.substring(textName.lastIndexOf("\\")+1);
            this.style.display="none";
            CreateFile();
            var tempid=this.id+"text";
            var temptext=textName+"<span style=\"cursor:hand;\" onclick=\"Del('"+tempid+"'),Del('"+this.id+"')\">删除</span>";
            CreateText(tempid,temptext);
        }
    }
    container.appendChild(input);
    inputCount++;
    }
    /*检测是否有同名文件*/
    function CheckFileName(txt)
    {
        var container=document.getElementById("fileUpArea");
        var ch=container.getElementsByTagName("input");
        var rvalue=true;
        if(ch.length>=2)
        {
            for(i=0;i<ch.length-1;i++)
            {
                if(ch[i].value==txt)
                {
                    alert("你已经添加了相同的附件!!!");
                    rvalue= false;
                    break;
                }
            }
        }
        return rvalue;
    }
    /*检测Element数量 如果节点数目大于等于max则返回false*/
    function CheckFileNum(max){
        var container=document.getElementById("fileUpArea");
        var ch=container.getElementsByTagName("input");
        if(ch.length-1>=5){
         alert("附件最多为"+max+"个!");
         return false;
        }
        return true;
    }
    /*创建显示的文件名称*/
    function CreateText(id,text)
    {
        var contxt=document.createElement("div");
        contxt.id=id;
        contxt.innerHTML=text;
        document.getElementById("filetxt").appendChild(contxt);
    }
    //del by id
    function Del(id)
    {
    document.getElementById(id).parentNode.removeChild(document.getElementById(id));
    }
    html
    ----------------------------
    <head>
    </head>
    <script language="javascript" type="text/javascript">
    window.onload=CreateFile;
    </script>
    <body>
    <form name="uploadForm" method="post" enctype="multipart/form-data" action="upload.do">
    <div id="fileUpArea" class="fileUpArea">
    </div>
    </form>
    <div id="filetxt"></div>
    </body>
    </html>