有時候頁面需要截取檔案的檔案名稱,在網上看到一段不錯的執行個體,轉來與大家分享,感謝原作者。
Code:
- <!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>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="Keywords" content="簡單的XHTML頁面" />
- <meta name="Description" content="這是一個簡單的XHTML頁面" />
- <title>簡單的XHTML頁面</title>
- </head>
- <body>
- <script language="javascript">
- function test(){
- var str1=document.Form1.fileFile1.value;
- var regstr=////;
- var regresult=new RegExp(regstr)
- var sss=str1.split(regresult,'100');
- var need=sss[sss.length-1];
- var a=need.split('.');
- document.Form1.txtText2.value=a[0];
- document.Form1.txtText3.value=a[1];
- }
-
- </script>
- <body>
- <form name=Form1>
- File Input:<input name=fileFile1 type=file><br>
-
- Text1:<input name=txtText1 type="text" size=60><br>
- Text2:<input name=txtText2 type="text"><br>
- Text3:<input name=txtText3 type="text"><br>
- <input type="button" value="測試" onclick="txtText1.value=fileFile1.value"><br><br>
- <input type="button" value="轉換" onclick="test()">
- </form>
- </body>
- </body>
- </html>
轉自:http://www.cnblogs.com/JustinYoung/articles/969900.html