多张图片预览同步上传js

/**
 * Created by liujing on 2017/5/10.
 */
$(document).ready(function($) {
    function changef(which,bulk,name_n){
        var bulka = bulk;
        var thisid = which.attr("id");
        var f = which.prop ('files')[0];
        var filename = f.name;
        var mime = filename.toLowerCase().substr(filename.lastIndexOf("."));
        var liid = $("#"+thisid).closest("li").attr("id");
        var liidb = parseInt(liid)+1;
        if(mime==".jpg" || mime==".png"){
            var src = window.URL.createObjectURL(f);
            var name =  $("#logo"+liid).val().split("\\").pop();
            $('#logotips'+liid).css({"background":'url('+src+')','backgroundSize':100+'%'});
            $('#up_flower'+liid).empty().append(name);
            $('#'+liid).append('');
            bulka.append('
  • liidb+'">liidb+'">liidb+'" type="file" name="'+name_n+'" id="logo'+liidb+'">
  • '
    ); $('#logotips'+liidb).css({"background":'url("../../img/c_up.png")','backgroundSize':100+'%'}); } $('.logo'+liid).addClass("newc"+liid); $('.newc'+liid).removeClass("logo"+liid); $('.newc'+liid).on('change',function(){ var files = $(this).prop('files')[0]; var srcb = window.URL.createObjectURL(files); var liid = $("#"+thisid).closest("li").attr("id"); var liidb = parseInt(liid)+1; var name = $("#logo"+liid).val().split("\\").pop(); $('#logotips'+liid).css({"background":'url('+srcb+')','backgroundSize':100+'%'}); $('#up_flower'+liid).empty().append(name); }) $('.edit_text').on('click',function(){ $(this).parent().remove(); }) } function changelast(which ,bulk){ var bulka = bulk; var thisid = which.attr("id"); var f = which.prop ('files')[0]; var filename = f.name; var mime = filename.toLowerCase().substr(filename.lastIndexOf(".")); var liid = $("#"+thisid).closest("li").attr("id"); var liidb = parseInt(liid)+1; if(mime==".jpg" || mime==".png"){ var src = window.URL.createObjectURL(f); var name = $("#logo"+liid).val().split("\\").pop(); $('#logotips'+liid).css({"background":'url('+src+')','backgroundSize':100+'%'}); $('#up_flower'+liid).empty().append(name); $('#'+liid).append(''); } $('.logo'+liid).addClass("newc"+liid); $('.newc'+liid).removeClass("logo"+liid); $('.newc'+liid).on('change',function(){ var files = $(this).prop('files')[0]; var srcb = window.URL.createObjectURL(files); var liid = $("#"+thisid).closest("li").attr("id"); var liidb = parseInt(liid)+1; var name = $("#logo"+liid).val().split("\\").pop(); $('#logotips'+liid).css({"background":'url('+srcb+')','backgroundSize':100+'%'}); $('#up_flower'+liid).empty().append(name); }) $('.edit_text').on('click',function(){ $(this).parent().remove(); }) } $(".logo1").one("change",function(){ that = $(this); var bulk = $("#add_beo"); var name = $(this).attr('name'); changef(that,bulk,name); }); $("#add_beo").one("change",".logo2",function(){ that = $(this); var bulk = $("#add_beo"); var name = $(this).attr('name'); changef(that,bulk,name); }); $("#add_beo").one("change",".logo3",function(){ that = $(this); var bulk = $("#add_beo"); var name = $(this).attr('name'); changef(that,bulk,name); }); $("#add_beo").one("change",".logo4",function(){ that = $(this); var bulk = $("#add_beo"); var name = $(this).attr('name'); changef(that,bulk,name); }); $("#add_beo").one("change",".logo5",function(){ that = $(this); var bulk = $("#add_beo"); changelast(that , bulk); }); });

    你可能感兴趣的:(多张图片预览同步上传js)