简体   繁体   中英

Getting values from different input fields with same class name

I'm working on an image sharing site, and right now I'm working on rendering out a users albums on a page. Each of the albums contains of at least on image, and I want to show all the albums as boxes with four thumbnails (the first four images in the album) in each of the boxes.

The images file names is stored in the value of a hidden input field in each of the boxes, and what I want to do is to get all the file names from each of the album boxes and show them as thumbnails.

The part that I need help with is how I shall get the file names from each of the album boxes, one by one. The code below doesn't work by obvious reasons, but how can it be rewritten so it works? All the input fields has the same class name.

Thanks in advance!

    if ($('.hiddenAlbumNames').length > 0){

        var images = $(this).val();

                    // the rest of the code (creating images and putting them in the album boxes)
    }

you have to loop the $('.hiddenAlbumNames') jQuery collection to get the values of all your input

$('.hiddenAlbumNames').each(function() {
       console.log( $(this).val() );
       /* rest of the code for each name retrieved */
})

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