zoukankan      html  css  js  c++  java
  • JS判断上传图片格式是否正确

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>JS判断上传图片格式是否正确</title>
    </head>
    <body>
    <input type="file" id="file"/>
    <input id="btn" type="button" value="button"/>
    <script>
        function isPicFile(fileName) {
            //lastIndexOf如果没有搜索到则返回为 -1
            if (fileName.lastIndexOf(".") != -1) {
                var fileType = (fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length)).toLowerCase();
                var suppotFile = new Array();
                    suppotFile[0] = "jpg";
                    suppotFile[1] = "gif";
                    suppotFile[2] = "bmp";
                    suppotFile[3] = "png";
                    suppotFile[4] = "jpeg";
                for ( var i = 0; i < suppotFile.length; i++) {
                    if (suppotFile[i] == fileType) {
                        return true;
                    } else {
                        continue;
                    }
                }
                alert("文件类型不合法,只能是jpg、gif、bmp、png、jpeg、png类型!");
                return false;
            } else {
                alert("文件类型不合法,只能是 jpg、gif、bmp、png、jpeg、png类型!");
                return false;
            }
        }
    
        var oFile = document.getElementById('file');
        var oBtn = document.getElementById('btn');
        oBtn.onclick = function () {
            isPicFile( oFile.value );
        };
    </script>
    </body>
    </html>
  • 相关阅读:
    线性回归问题
    聚类:层次聚类
    聚类:(K-means)算法
    神经网络算法
    AutoEventWireup解释
    asp.net中runat="server"的含义
    十步完全理解SQL
    sqlserver中分区函数 partition by的用法
    被忽略却很有用的html标签
    net中使用母版页
  • 原文地址:https://www.cnblogs.com/codinganytime/p/5227666.html
Copyright © 2011-2022 走看看