1.无插件预览(window.URL.createObjectURL)

```javascript
//demo 图片预览  单个
$(".demo input#demo_file").on("change",function(){
    var val_1 = $(this).val();
    var valImg = window.URL.createObjectURL(document.getElementById("demo_file").files[0]);//成功预览该图片
    $(".demo div img").attr("src",valImg);
});
 
 
2.多个预览 上传
//得支持同时上传多个
$(".imgButton_w").on("click",function(){
    console.log(1);
    var $input = "<input type='file' id='img_' name='file' class='files'>";
    $("#input_files").append($input);
    $("#input_files input:last-child").trigger("click").siblings().removeAttr("id");
});
var imgArr = [];
function addFunc(){
    var val_ = $("#input_files input:last-child").val();
    var newVal = val_.split(".");
    var reg_ = /^(jpg|png|jpeg|gif)$/;
    if(val_!==''&&!reg_.test(newVal[newVal.length-1])) {
        alert("请上传后缀为jpg、png、jpeg、gif的图片!");
        return false;
    }
    var valImg = window.URL.createObjectURL(document.getElementById("img_").files[0]);//成功预览该图片
    imgArr.push(valImg);
    var $html = '<div class="upload_append_list"><p>' +
        '<a href="javascript:" class="upload_delete delete" title="删除" data-index="">删除</a><br />' +
        '<img id="uploadImage_" src="' + valImg + '" class="upload_image" /></p>' +
        '<span id="img" class="upload_progress"></span>' +
        '</div>';
    $("#preview").append($html);
}
//创建数组存储图片信息  最多9张图,
function max_nine(){
    var length_ = $(".show_img > div").size();
    console.log("length_:"+length_);
    if(length_ >=9){
        alert("最多只能上传9张图!");
    }else{
        addFunc();
    }
}
$(".upload_img ").on("click",function(){
    max_nine();
});
//移除预览但未上传给后台的图片
$(document).on("click","#preview p a.delete",function() {
    var i = $(this).parent().parent().index();
    $("#input_files input").eq(i).remove();
    $(this).parent().parent().remove();//alert("删除预览");
});
function uploadFunc(){
    $("#imgForm").ajaxSubmit({
        type: "post",
        url: "/investManage/financing/addImg.do",
        data: {"projectId":localStorage.projectId},
        dataType: "json",
        success: function (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);
            }
        },
        error: function () {
            alert("服务器错误,上传图片失败!");
        }
    });
}
```

上传预览图片自己做的.md的更多相关文章

  1. 微信开发中使用微信JSSDK和使用URL.createObjectURL上传预览图片的不同处理对比

    在做微信公众号或者企业微信开发业务应用的时候,我们常常会涉及到图片预览.上传等的处理,往往业务需求不止一张图片,因此相对来说,需要考虑的全面一些,用户还需要对图片进行预览和相应的处理,在开始的时候我使 ...

  2. 上传预览图片的插件jquery-fileupload

    上传预览图片的插件jquery-fileupload github地址:https://github.com/blueimp/jQuery-File-Upload 中文文档:http://www.jq ...

  3. 异步上传&预览图片-不压缩图片

    本例使用ajaxFileUpload异步上传预览图片 <bean id="multipartResolver" class="org.springframework ...

  4. 异步上传&预览图片-压缩图片

    移动端普及的时代,流量是用户最关心的,手机拍出来的照片基本上都在1~2M以上,这样上传会非常耗流量,影响用户体验,此例能在保证清晰度的情况下,将4.5M的图片压缩为30K <!DOCTYPE h ...

  5. html 上传预览图片

    直接上代码了 <!DOCTYPE html> <html><head lang="en"><meta http-equiv="C ...

  6. javascript 上传 预览图片 兼容 谷歌 ie

    最近的项目要用到这块,但是在网上找了很多资料,很多都是假的,都不行,最后终于找到一个,还是可以兼容主流的,特分享给大家,可以用 <!DOCTYPE html PUBLIC "-//W3 ...

  7. Vue 中使用 viewerjs进行本地上传预览图片

    https://www.cnblogs.com/shenjp/p/9754171.html 如果图片路径是 接口的返回信息的话,将路径存储在数组中,在this.$nextTick中实例化Viewer: ...

  8. [前端 4] 使用Js实现图片上传预览

    导读:今天做图片上传预览,刚开始的做法是,先将图片上传到Nginx,然后重新加载页面才能看到这个图片.在这个过程中,用户一直都看不到自己上传的文件是什么样子.Ps:我发现我真的有强迫症了,都告诉我说不 ...

  9. ASP.NET工作笔记之一:图片上传预览及无刷新上传

    转自:http://www.cnblogs.com/sibiyellow/archive/2012/04/27/jqueryformjs.html 最近项目里面涉及到无刷新上传图片的功能,其实也就是上 ...

随机推荐

  1. HDU 4006 优先队列

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  2. HTML input文本框设置和移除默认值

    这里想实现的效果是:设置和移除文本框默认值,如下图鼠标放到文本框中的时候,灰字消失. 1.可以用简单的方式,就是给input文本框加上onfocus属性,如下代码: <input id=&quo ...

  3. Iconfont矢量图标平台全面升级

    阿里UX矢量图标库今天全新发布上线了,这次升级相对于老版本做了30多项功能和体验上的改善:赶快来体验一下吧!! 请猛戳:www.iconfont.cn 请猛戳:www.iconfont.cn 设计师p ...

  4. jquery_事件与动画

    事件绑定 bind(type[,data],fn)(无限触发) type:事件类型包括jquery中已有事件也可以自定义事件 data:可选参数,作为event.data属性传递给事件对象的额外数据对 ...

  5. IOS第16天(5,Quartz2D雪花)

    *** #import "HMView.h" @interface HMView() { int count; } @property (nonatomic, assign) CG ...

  6. A trip through the Graphics Pipeline 2011_08_Pixel processing – “fork phase”

    In this part, I’ll be dealing with the first half of pixel processing: dispatch and actual pixel sha ...

  7. Yii源码阅读笔记(二十三)

    Module类中的辅助功能方法: /** * Returns an ID that uniquely identifies this module among all modules within t ...

  8. String与StringBuilder之间区别(转)

    当我们在初学使用C#时,常常会不知道该用StringBuilder合适还是用String高效,下面是我在学习当中对StringBuilder和String的区别总结,分享给大家. String类有不可 ...

  9. 【转】Unity中的协同程序-使用Promise进行封装(一)

    原文:http://gad.qq.com/program/translateview/7170767 译者:陈敬凤(nunu)    审校:王磊(未来的未来) 每个Unity的开发者应该都对协同程序非 ...

  10. (IOS)BaiduFM 程序分析

    本文主要分享下楼主在学习Swift编程过程中,对GitHub上的一个开源app BaiduFM的研究心得. 项目地址:https://github.com/belm/BaiduFM-Swift 一.项 ...