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