就是用button模拟file按钮的click() 并将file。value赋给text。value  
提交的时候file里为什么空了 
我并没有给file赋值 只是把file的值赋给text
估计是用button代替file时出的问题
很棘手阿主要的代码  上传处理页uploadscript.asp没有问题  
我想模拟一个File 
用button模拟file。click() 把file。value赋给Text0。value  
 
 <html  >  
 <head  >  
 <meta  http-equiv=  "Content-Type  "  content=  "text/html;  charset=gb2312  "  >  
 <title  >上传页面  </title  >  
 <script  language=  "javascript  "    >    
var  num=1;  
   
 
function      HandleFileButtonClick(num)        
{        
w=document.forms[0].elements[num];  
w.click();  
       
}      
 
 </script  >  
 </head  >  
 <body  >  
 <form  name=  "form1  "  action=  "uploadscript.asp  "  method=  "post  "  "  enctype=  "multipart/form-data  "  >  
 <input      type=  "file  "      name=  "myFile0  "  onchange=  "Text0.value=this.value  "  >    
 <input      type=  "text  "      name=  "Text0  "      readonly=  "true  "  >    
                                 
                     <!--      Button      to      invoke      the      click      of      the      File      Input      --  >        
                     <input      type=  "button  "      onclick=  "HandleFileButtonClick(0);  "      value=  "Upload      File  "  >    
 <br  >        
   <input  align=  "bottom  "  type=  "submit  "  name=  "submit  "  value=  "提交  "    >  
 
 </body  >  
 </html  >

解决方案 »

  1.   

    由于安全性的原因,即使你模拟了,在某些浏览器中页不能提交过去的,你要做的就是让点“浏览…”这个按钮选择文件,不要用其它方法触发它的click事件
      

  2.   

    我觉得也是安全问题 可是我想隐藏 file
    请问一下动态增加file个数 又没有什么办法让原来file的值不变成空的
      

  3.   

    file控件似乎是无法在js中初始化其值的
    如果想多个file,可以在修改file控件的onclick方法,赋值本控件后隐藏掉,然后在原有位置生成一个新的。但是还涉及到显示,删除已赋值的那些控件,要求你对js比较熟悉才行
      

  4.   

    美化文件上传控件
    http://591wap.cn/translate/inputfile/inputfile.html
    原文地址:http://www.quirksmode.org/dom/inputfile.html