Home > Web Front-end > JS Tutorial > body text

js file format verification

大家讲道理
Release: 2016-11-10 13:14:08
Original
1193 people have browsed it

<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>
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!