JavaScript 判断文件扩展名

<html>
  <head>
    <title>JS判断文件扩展名</title>
    <script language="javascript" type="text/javascript">
      function CheckInput()
      {
        var file = encodeURI(document.getElementById("file").value);
        if(file == "") {
           alert("文件不能为空!");
        } else {    
           var extension = file.substring(file.lastIndexOf('.'), file.length).toLowerCase();                
           alert(extension);                            
        } 
      }   
    </script>
  </head>
 
  <body>
    <table>
      <tr>
        <td>
          <input type="file" name="file" id="file">
          <input type="button" name="button" id="button" value="button" onclick="return CheckInput();">
        </td>
      </tr>
    </table>
  </body>
 
</html>

你可能感兴趣的:(JavaScript)