标签: Gravity Forms
-
作者帖子
-
<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 使用多文件上传文件的功能时,同一个表单内可以拿到单文件输入框的信息,拿不到多文件输入框的信息问题可能出在您的代码中,您正在尝试通过索引来访问多文件上传输入框的文件信息。然而,多文件上传输入框返回的是一个文件数组,而不是单个文件对象。
要获取多文件上传输入框的文件信息,您需要使用循环来遍历文件数组,并逐个访问每个文件对象的属性。以下是修改后的代码示例:
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
函数来遍历每个文件输入框,而不是通过索引直接访问。
以上由壳壳虫自动解答供参考,您可以继续跟帖或等待人工回复。
-
作者帖子
- 哎呀,回复话题必需登录。