JavaScript擷取當前檔案全路徑 檔案名稱 檔案上傳對話方塊路徑 檔案夾名 檔案名稱

來源:互聯網
上載者:User

  

 1 //1******** 擷取檔案上傳對話方塊中的全路徑 2  3 <script type="text/javascript"> 4            function upload() { 5                var filename = document.getElementById("importFile").value; 6                alert(filename); 7            } 8 </script> 9 10 11 //html12            <input type="file" id="importFile" />13             <input type="button" onclick="upload()"/>

 

 1  //2******** 擷取檔案上傳對話方塊中的路徑檔案夾名 2   3   <script type="text/javascript"> 4              var filename = document.getElementById("importFile").value; 5                alert(filename); 6  7                var sFileName = new Array(); 8                sFileName = filename.split('\\'); 9 10                len = sFileName.length11                var thisFileName = sFileName[len - 2]12                alert(thisFileName);13  </script>14  15  16  //html17             <input type="file" id="importFile" onclick="upload()“/>18              <input type="button" onclick="upload()"/>

 

 1 //3***********擷取當前檔案全路徑 2  3 <script language="javascript">  4  5      alert(window.location.href);  6  7      alert(window.location);  8  9      alert(location.href); 10 11      alert(parent.location.href); 12 13      alert(top.location.href); 14 15      alert(document.location.href); 16 17      alert(document.URL);18 19 </script>20 21 //4*************擷取當前頁面所在的目錄方法22 23 <script type="text/javascript">24 25      //方法一26 27      var str = location.href;28 29      var arr = str.split("/");30 31      delete arr[arr.length-1];32 33      var dir = arr.join("/");34 35      alert(dir);36 37     //方法二38 39      alert(location.href.substring(0,location.href.lastIndexOf('/')));40 41 </script>42 43  44 45 //5*******************擷取當前頁面所在的檔案名稱46 47 <script   language=javascript>   48 49     var  filename=location.href;50 51     filename=filename.substr(filename.lastIndexOf('/')+1);   52 53    alert(filename);   54 55 </script>

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.