首页 > 建站教程 > JS、jQ、TS >  JS判断文件类型的方法正文

JS判断文件类型的方法

function changeType(objFile) {
    var objtype=objFile.substring(objFile.lastIndexOf(".")).toLowerCase();
    var fileType=new Array(".ad",".adprototype",".asa",".asax",".ascx",".ashx",".asmx",".asp",".aspx",".axd",".browser",".cd",".cdx",".cer",".compiled",".config",".cs",".csproj",".dd",".exclude",".idc",".java",".jsl",".ldb",".ldd",".lddprototype",".ldf",".licx",".master",".mdb",".mdf",".msgx",".refresh",".rem",".resources",".resx",".sd"+".sdm",".sdmdocument",".shtm",".shtml",".sitemap",".skin",".soap",".stm",".svc",".vb",".vbproj",".vjsproj",".vsdisco",".webinfo");
    for(var i=0; i<fileType.length; i++){
        if(objtype==fileType[i])
        {
             return false;
             break;
        }
    }
    return true;
}
上面代码实现了JS判断文件类型的方法,如果你上传或者文件操作的文件类型,与你定义的文件类型相同,则返回flase,否则返回true。