jQuery实现多文件的预览显示和上传

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29656961/article/details/80594093
<div id="DisplayGalleryImage"> 
   <div id="galleryImage-container"> 
    <div class="img-up-add img-item addGallery"> 
     <span class="img-add-icon">+</span> 
    </div> 
    <input type="file" name="files" id="galleryImage" multiple="" /> 
   </div> 
  </div>

$(".addGallery").click(function() {
    $("#galleryImage").click();
});
$("#galleryImage").change(function() {
    for (var i = 0; i < this.files.length; i++) {
        imgpath = getObjectURL(this.files[i]);
        $("#galleryImage-container").prepend("<div class='img-thumb img-item galleryImage' data-index='" + index + "'><img class='thumb-icon' src='" + imgpath + "' data-index='" + index + "'><div class='img-remove removeGalleryImg' data-xindex='" + (index++) + "' >x</div></div>");
    }
});
$("body").on("click", ".removeGalleryImg",
function() {
    var num = $(this).attr("data-xindex");
    $("div[data-index=" + num + "]").remove();
});

展开阅读全文

没有更多推荐了,返回首页