且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JS判断文件扩展名

更新时间:2022-08-17 22:34:59

JS判断文件扩展名

 


  1. <html> 
  2.   <head> 
  3.     <title>JS判断文件扩展名</title> 
  4.     <script language="javascript" type="text/javascript"> 
  5.       function CheckInput() 
  6.       { 
  7.         var file = encodeURI(document.getElementById("file").value); 
  8.         if(file == "") { 
  9.            alert("文件不能为空!"); 
  10.         } else {     
  11.            var extension = file.substring(file.lastIndexOf('.'), file.length).toLowerCase();                 
  12.            alert(extension);                             
  13.         }  
  14.       }    
  15.     </script> 
  16.   </head> 
  17.   
  18.   <body> 
  19.     <table> 
  20.       <tr> 
  21.         <td> 
  22.           <input type="file" name="file" id="file"> 
  23.           <input type="button" value="检测" onclick="return CheckInput();"> 
  24.         </td> 
  25.       </tr> 
  26.     </table> 
  27.   </body> 
  28.   
  29. </html> 

 




      本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/942018,如需转载请自行联系原作者