zoukankan      html  css  js  c++  java
  • js jquery 上传文件格式大小判断简单总结

    大家好我是床前明月光,疑是地上霜

    // html

    <a href="javascript:;" class="file">添加附件
    <input type="file" name="" id="fileId" onchange="upload()">
    </a>
    /**判断上传文件文件格式**/
    var filePath ="";
    var fileType ="";
    function upload(){
    var fileName = $('#fileId').val().split('\'); //得到文件名数组
    var fileSize = document.getElementById('fileId').files[0]; //获得文件大小;
    fileName2 = fileName[fileName.length-1]; // 获得文件名
    filePath = $('#fileId').val().toLowerCase().split(".");
    fileType = filePath[filePath.length - 1]; //获得文件结尾的类型如 zip rar 这种写法确保是最后的
    $('.errHint').show().text(fileName[2]);
    console.log(filePath);
    console.log(fileType);
    if(!(fileType == "png" || fileType == "jpg" || fileType == "xlsx"|| fileType == "docx"|| fileType == "rar" || fileType == "zip" )){
    $('.errHint').show().text('文件格式不符合要求!')
    }else if(fileSize.size>10485760){
    $('.errHint').show().text('错误!请上传不超过10M的文件');
    return
    }
    }
    拷贝直接用即可
  • 相关阅读:
    IOC和DI的区别
    hdu 1217(Floyed)
    hdu 2112(字典树+最短路)
    hdu 4081(次小生成树)
    hdu 1811(缩点+拓扑排序+并查集)
    poj 3026(BFS+最小生成树)
    hdu 3635(并查集)
    hdu 3047(扩展并查集)
    hdu 1116(并查集+欧拉路径)
    poj 1679(次小生成树)
  • 原文地址:https://www.cnblogs.com/zou1234/p/7976464.html
Copyright © 2011-2022 走看看