Gravity Forms 使用多文件上传文件的功能无法拿到文件信息

Gravity Forms 使用多文件上传文件的功能无法拿到文件信息


标签: 

  • 该话题包含 1 个回复,2 人参与,最后由 壳壳虫 更新于 6月 前
正在查看 2 个帖子:1-2 (共 2 个帖子)
  • 作者
    帖子
  • changhongshan
    参与者
    • 文章数量: 17
    @changhongshan
    楼主

    <div class=”registration_form” style=”margin-top:222px;”>
    <?php echo do_shortcode(‘[gravityform id=”15″ title=”false” description=”false”]’); ?>
    <button id=”demobtn” style=”width=200px;height=100px”>点击</button>
    </div>
    <script>
    jQuery(document).ready(function($){
    console.log($(“input[type=file]”));
    $(“#demobtn”).click(()=>{
    console.log($(“input[type=file]”));
    console.log($(“input[type=file]”)[0].files); // 单文件上传的可以输出信息
    console.log($(“input[type=file]”)[1].files); // 多文件上传的输出undefined
    })
    })
    </script>
    在使用Gravity Forms使用多文件上传文件的功能时,同一个表单内可以拿到单文件输入框的信息,拿不到多文件输入框的信息

    壳壳虫
    参与者
    • 文章数量: 298
    @kekechong

    问题可能出在您的代码中,您正在尝试通过索引来访问多文件上传输入框的文件信息。然而,多文件上传输入框返回的是一个文件数组,而不是单个文件对象。

    要获取多文件上传输入框的文件信息,您需要使用循环来遍历文件数组,并逐个访问每个文件对象的属性。以下是修改后的代码示例:

    jQuery(document).ready(function($){
        console.log($("input[type=file]"));
        $("#demobtn").click(() => {
            console.log($("input[type=file]"));
            $("input[type=file]").each(function(index, input) {
                console.log(input.files); // 输出每个文件输入框的文件信息
            });
        });
    });

    这样,您将能够通过循环访问多文件上传输入框的文件信息。请注意,这里使用了each函数来遍历每个文件输入框,而不是通过索引直接访问。


    以上由壳壳虫自动解答供参考,您可以继续跟帖或等待人工回复。

正在查看 2 个帖子:1-2 (共 2 个帖子)
  • 哎呀,回复话题必需登录。

未找到对应子版块?请直接在 [疑难杂症] 版块中发帖提问。

收藏纪念品


有奖活动

参与论坛社区问答,有机会获赠文派瓦普(Wapuu.com)手办模型。

产品博客


RSS 错误: http://blog.weixiaoduo.com/feed is invalid XML, likely due to invalid characters. XML error: Invalid document end at line 2, column 1

话题信息

商业系统