简体   繁体   中英

Image Picker jquery plugin:How to get img-src of selected images(multiple selection case)

I am using this Image Picker jQuery plugin ( http://rvera.github.io/image-picker/ ) and want to get img-src of selected images.

In one selection case I try this and all is work fine.

$(".image-picker").imagepicker({

            clicked:function(){
      alert($(this).find("option[value='" + $(this).val() + "']").data('img-src'));
  }

        }); 

so if I want to get img-src of all images that was selected(in multiple selection case) and collect all of that in array.Is there anyway?

    var req = $("div[class='thumbnail selected']").children('img');
    var imagessource = [];
    $(req).each(function (datakey, datavalue) {
        src =  $(datavalue).attr('src'); 
        imagessource.push(src);
      });
      console.log(imagessource);

Get an object with all the selected image, then iterate to extract each image source

You can always access your multiple list like this:

$("*[multiple=multiple]").find("option:selected").each(function(index, item){
    console.log($(item).attr("data-img-src"));
});

Of course, replace "*[multiple=multiple]" selector with your element identifier, since this way you will get all multiple lists from the page.

If you don't want to do it that way, the other way to do this, since image picker plugin is adding "selected" class on div's that are wrapping your images, would be to use that to get all selected images:

$(".image-picker").find(".selected img").each(function(index, item){
    console.log($(item).attr("src"));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM