JS实现多张图片预览同步上传功能
程序员文章站
2022-11-19 22:30:38
废话不多说了,直接给大家贴代码了,具体代码如下所示:
/**
* created by liujing on 2017/5/10.
*/
$(docum...
废话不多说了,直接给大家贴代码了,具体代码如下所示:
/** * 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('<a class="edit_text">✖</a>'); bulka.append('<li class="uploading" id="'+liidb+'"><a class="a_a" id="logotips'+liidb+'"><input class="input_hide logo'+liidb+'" type="file" name="'+name_n+'" id="logo'+liidb+'"></a></li>'); $('#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('<a class="edit_text">✖</a>'); } $('.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实现多张图片预览同步上传功能,希望对大家有所帮助
上一篇: PHP获取链表中倒数第K个节点的方法
下一篇: 剪映如何添加滚动字幕?