標籤: 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
函數來遍歷每個文件輸入框,而不是通過索引直接訪問。
以上由殼殼蟲自動解答供參考,您可以繼續跟帖或等待人工回覆。
-
作者帖子
- 哎呀,回覆話題必需登錄。