Home  >  Article  >  Web Front-end  >  js file format verification

js file format verification

大家讲道理
大家讲道理Original
2016-11-10 13:14:081248browse

<html>
   
  <head>
   <title>js校验文件格式</title>
   <meta http-equiv=&#39;content-type&#39; content=&#39;text/html;charset=utf-8&#39;>
   <script type="text/javascript" src="jquery-1.4.3.js"></script>
   <script type="text/javascript">
    
     function get(){
      var s = $("#file1").val();
      var fl = s.split(".");
   //常用的文件格式
      var ary = ["doc","docx","xls","xlsx","ppt","gif","jpeg","jpg","png","txt","wps","pdf"];
        
      //文件格式在数组中返回下标,否则返回 -1
     var t= $.inArray(fl[1],ary);
      
     return t==-1;
     
     }
     
   </script>
  </head>
  <body>
   
    <input type="file" id="file1"  >
    <input type="button" onclick="get();" value="文件格式">
  </body>
  
</html>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Time in JavascriptNext article:Time in Javascript