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

Getting values from different input fields with same class name

本文关键字:输入 字段 获取 同类      更新时间:2023-09-26

我正在开发一个图像共享网站,现在我正在页面上渲染用户相册。每个相册至少包含图像,我想将所有相册显示为每个框中有四个缩略图(相册中的前四个图像)的框。

图像文件名存储在每个框中隐藏输入

字段的值中,我想做的是从每个相册框中获取所有文件名并将它们显示为缩略图。

我需要帮助的部分是如何从每个相册框中逐个获取文件名。下面的代码由于明显的原因不起作用,但是如何重写它以使其工作?所有输入字段都具有相同的类名。

提前感谢!

    if ($('.hiddenAlbumNames').length > 0){
        var images = $(this).val();
                    // the rest of the code (creating images and putting them in the album boxes)
    }

你必须循环$('.hiddenAlbumNames') jQuery集合来获取所有输入的值

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