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. zk编程语言: 如何改变datebox框值的大小及高度

    <?page title="" contentType="text/html;charset=UTF-8"?> <zk > <st ...

  2. c#语句 for循环嵌套

    1.打印三角形. 1) 方法一.for嵌套 方法二.只用一个for 2)倒三角 3)后三角 2.求100以内质数的和. 3.一张纸厚度为0.01米,至少对折多少次才能达到珠峰的高度?(用for死循环) ...

  3. Greenplum 生成加分区语句

    在使用greenplum中会使用分区表,但同时分区表需要维护分区:比如加分区,这个过程比较痛苦,查询相关资料以后有了相应的解决办法,但是该办法也不是万能的,有诸多限制,关于限制有兴趣的同学可以查看我文 ...

  4. Chrome开发,debug的使用方法。

    怎样打开Chrome的开发者工具? 你可以直接在页面上点击右键,然后选择审查元素: 或者在Chrome的工具中找到: 或者,你直接记住这个快捷方式: Ctrl+Shift+I (或者Ctrl+Shif ...

  5. NYOJ背包问题

    #include <stdio.h> struct group{ int value; int weight; }; void Sort(group bag[],int num) { in ...

  6. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(可持久化Trie)

    D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  7. Code Snippet

    Code Snippet: http://msdn.microsoft.com/en-us/library/z41h7fat.aspx CodePlex.Snippets 4.0 - Visual S ...

  8. 详解依赖注入(DI)和Ioc容器

    简单的来说,关键技术就是:注册器模式. 场景需求 我们知道写一个类的时候,类本身是有个目的的,类里面有很多方法,每个方法搞定一些事情:我们叫这个类为主类. 另外这个主类会依赖一些其他类的帮忙,我们叫这 ...

  9. golang的cgo支持调用C++的方法

    1)swift,貌似官网的推荐 2)extern "C" 我使用后者,用起来比较爽,上代码 c.h #pragma once #ifdef __cplusplus extern & ...

  10. am335x 更改调试串口

    /********************************************************************* * am335x 更改调试串口 * * am335x的调试 ...