Gravity Forms 使用多檔案上傳檔案的功能無法拿到檔案資訊

標籤: 

正在檢視 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 使用多檔案上傳檔案的功能時,同一個表單內可以拿到單檔案輸入框的資訊,拿不到多檔案輸入框的資訊

    殼殼蟲
    參與者
    • 文章數量: 328
    @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 個帖子)
  • 哎呀,回覆話題必需登入。

話題資訊

  • 當前位於:Gravity Forms
  • 1 條回覆
  • 2 個參與人
  • 最後回覆:<a href="https://bbs.weixiaoduo.com/users/kekechong/" title=" 檢視殼殼蟲的個人資料" class="bbp-author-link"><span class="bbp-author-name"> 殼殼蟲</span></a>
  • 上次活動:<a href="https://bbs.weixiaoduo.com/topic/42782/#post-42783" title=" 回覆至:Gravity Forms 使用多檔案上傳檔案的功能無法拿到檔案資訊">1 年、 4 月前</a>