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

时间:2016-07-15 11:08:34

标签: javascript jquery jquery-file-upload

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

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

我使用此代码:

 $("#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");

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

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

1 个答案:

答案 0 :(得分:0)

您可以尝试使用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>