代码如下:
    脚本文件
   <script type="text/javascript">
     function openWindow(){
       var savePath;
           var objSrc=new ActiveXObject("Shell.Application").BrowseForFolder(0,'请选择文件目录:',0,'');
            
            if(objSrc!=null){
             savePath=objSrc.Items().Path;
             document.all.savePath.value=savePath;       } 
     }
    </script>
    html文件
    <input type="text"  name="savePath"/>
        <input type="button" value="浏览..." onclick="openWindow()">
现在文本框中的值是undefined,不知道怎么回事,多谢了

解决方案 »

  1.   

    为啥要用js来写呢,上传只要一个file控件就可以了啊<input type="file" name="uploadFile" onchange="alert(this.value)">
      

  2.   

    还不如隐藏一个file控件,点击的时候调用file控件click事件,选择玩了,获取file控件的value,赋值给文本框。
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
      <input type="text" id="filepatn" name="filepath" /><input type="button" value="浏览" onclick="document.getElementById('filectl').click()">
      <input type="file" id="filectl" style="display:none;" onchange="document.getElementById('filepath').value=this.value;">
     </body>
    </html>