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:
- <input size=30 type="file" name="pic" onchange="check_type(this)"/>
- <script language="javascript">
- function check_type(obj){
- var Cycle = $ (Obj) Kvl ();
- var index=str.lastIndexOf('.');
- was strtype = str.substr (index, 4);
- strtype=strtype.toLowerCase();
- if(strtype!=".png" || strtype!=".jpg" || strtype!=".gif"){
- $(obj).val("");
- Alert ( "Please upload pictures gif, jpg, png format!" );
- }
- }
- </script>
Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2011/05/27/2060030.html