Rumah >hujung hadapan web >tutorial js >js文件格式校验
<html> <head> <title>js校验文件格式</title> <meta http-equiv='content-type' content='text/html;charset=utf-8'> <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>