如何在jQuery中存储多个输入图像的元素

How to store element of multiple input image in jQuery?

本文关键字:输入 图像 元素 存储 jQuery      更新时间:2023-09-26

你好,我是新手,对不起我的英语不好

我想将图像元素存储在变量中并发送到服务器。

我使用此代码:

 $("#input-fa").fileinput({
        showUpload: false,
        language: 'th',
        uploadUrl: "#",
        allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg'],
        overwriteInitial: false,
        maxFileSize: 1000,
        maxFileCount: 3,
        autoReplace: false
    });

在保存按钮功能中,我试试这个:

var myFile = $('#input-fa').prop('files');

var myFile = document.getElementById("input-fa");

问题是:如果我选择一两个图像一次,然后再浏览一两个,我将只得到我浏览的最后一个设置对象。

有没有办法让它可以浏览多次?

您可以尝试为此使用 AJAX:

<input id="input-fa" name="imageupload[]" type="file" multiple=true/>
<script>
$("#input-702").fileinput({
    uploadUrl: "http://localhost/file-loc/", // server upload action
    uploadAsync: true,
    minFileCount: 1,
    maxFileCount: 5,
    overwriteInitial: false,
});
</script>