zoukankan      html  css  js  c++  java
  • iframe模拟异步上传图片

    <iframe id="uploadframe" width="0" height="0" style="display:none;" name="upload_target"></iframe>
    
    <form id="uploadpic" target="upload_target" enctype="multipart/form-data" method="post" action="" style="display: none;">
    
    <input type="file" name="uploadImg" id="uploadImg">
    
    </form>
    
    $(function(){
    
    $("#uploadImg").change(function(){
    
       if($(this).val() && checkFile('uploadImg')){
    
    ​       $('#uploadpic').submit();
    
           $(this).val('');​
    
           return true;
    
           //$('#uploadpic').submit();​
    
       }
    
       return false;
    
    });
    
    });
    
    function checkFile(id)
    
    {
    
        extensions = 'jpg,gif,png,jpeg';
    
        var path = document.getElementByIdx_x_x_x_x_x_x(id).value;
    
        var ext = getExt(path);
    
        var re = new RegExp("(^|\s|,)" + ext + "($|\s|,)", "ig");
    
        if(extensions != '' && (re.exec(extensions) == null || ext == '')) {
    
            $.messager.alert("对不起,只能上传jpg, jpeg, png, gif类型的图片!");
    
            $('#'+id).val('');
    
            return false;
    
        }
    
        //showLoading();
    
        return true;
    
    }
    
    function getExt(path) {
    
        return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
    
    }
  • 相关阅读:
    数据结构笔记
    并查集
    计算两个数的最大公约数和最小公倍数
    行盒
    浏览器兼容性和布局
    Java中HashMap等的实现要点浅析
    关于js异步上传文件
    填充路径时所使用的 “非零环绕规则”
    XP极限编程
    假如森林里有一棵树倒下了
  • 原文地址:https://www.cnblogs.com/benlightning/p/4301786.html
Copyright © 2011-2022 走看看