多张图片,限制大小,格式.md

时间:2022-04-20 13:40:00
//判断图片大小和后缀 两张身份证照片大小
```javascript
$(".js_upFile").on("change",function(){
    //判断图片大小和后缀 两张身份证照片大小
        var val_ = $(this).val();
        var file_ = this.files;
        console.log(file_);
        var size_ = file_[0].size;
        console.log(size_);
        var size_M = size_ / (1024 * 1024);   //换成M单位,
        console.log(size_M);
        var newVal_ = val_.split(".");
        console.log(newVal_);
        var reg_suffix = /^(jpg|png)$/; //后缀限制
        var maxSize_ = 2; //最大2M
        if(val_==''||!reg_suffix.test(newVal_[newVal_.length-1])||size_M > maxSize_) {
            alert("请选择后缀为png,jpg,大小不超过2M的文件!");
            $(".js_upFile").val("");
            return false;
        }
});
 
var width_ = $(".show_picsize ").width();
    var height_ = $(".show_picsize ").height();
    console.log(width_);
    if(width_<200||height_<200){
        alert("请上传至少200*200的图片!");
        $("#upload-file").val("");
        return false;
    }
        $("form").ajaxSubmit({
            type: "POST",
            url: "/investManage/user/saveHeadIcon.do",
            dataType:'json',
            enctype: 'multipart/form-data',
            success: function(obj){
                console.log(obj);
                if(obj.login&&obj.status==1){
                    alert("上传成功");
                }else if(obj.login == false){
                    alert(obj.msg);
                    window.location.href = "login.html";
                }else{
                    alert(obj.msg);
                }
            }
        });
```