javascript截取路徑中的檔案名稱

來源:互聯網
上載者:User

 有時候頁面需要截取檔案的檔案名稱,在網上看到一段不錯的執行個體,轉來與大家分享,感謝原作者。

Code:
  1. <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <meta name="Keywords" content="簡單的XHTML頁面" />  
  6.     <meta name="Description" content="這是一個簡單的XHTML頁面" />  
  7.     <title>簡單的XHTML頁面</title>  
  8. </head>  
  9. <body>  
  10. <script   language="javascript">     
  11.   function   test(){     
  12.   var   str1=document.Form1.fileFile1.value;     
  13.   var   regstr=////;     
  14.   var   regresult=new   RegExp(regstr)     
  15.   var   sss=str1.split(regresult,'100');     
  16.   var   need=sss[sss.length-1];     
  17.   var   a=need.split('.');     
  18.   document.Form1.txtText2.value=a[0];     
  19.   document.Form1.txtText3.value=a[1];     
  20.   }     
  21.       
  22.   </script>     
  23.   <body>     
  24.   <form   name=Form1>     
  25.   File   Input:<input   name=fileFile1   type=file><br>     
  26.       
  27.   Text1:<input   name=txtText1   type="text"     size=60><br>     
  28.   Text2:<input   name=txtText2   type="text"><br>     
  29.   Text3:<input   name=txtText3   type="text"><br>     
  30.   <input   type="button"   value="測試"   onclick="txtText1.value=fileFile1.value"><br><br>     
  31.   <input   type="button"   value="轉換"   onclick="test()">     
  32.   </form>     
  33.   </body>  
  34. </body>  
  35. </html>  

轉自:http://www.cnblogs.com/JustinYoung/articles/969900.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.