简体   繁体   English

从具有相同类名的不同输入字段获取值

[英]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') jQuery集合以获取所有输入的值

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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