JavaScript Get upload file extension

When uploading a file to determine the type of the uploaded file meets the needs, access to upload the file extension using JavaScript. Presentation as follows:

    Source as follows:

 
  
  1. <input size=30 type="file" name="pic" onchange="check_type(this)"/> 
  2. <script language="javascript"
  3. function check_type(obj){ 
  4.         var  Cycle = $ (Obj) Kvl (); 
  5.         var index=str.lastIndexOf('.'); 
  6.         was  strtype = str.substr (index, 4); 
  7.         strtype=strtype.toLowerCase(); 
  8.         if(strtype!=".png" || strtype!=".jpg" || strtype!=".gif"){ 
  9.             $(obj).val(""); 
  10.             Alert ( "Please upload pictures gif, jpg, png format!" ); 
  11.         } 
  12.     } 
  13. </script>

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2011/05/27/2060030.html

Guess you like

Origin blog.csdn.net/weixin_33690963/article/details/93496115