我有一些java腳本功能。我正在使用輸入類型文件來選擇多個文件。在on-change事件中,我得到一個上傳的列表文件對象,然後我將這些對象存儲在一個隱藏的字段中。我想僅將這些對象作爲文件對象進行檢索。我怎麼能做到這一點?將Json對象轉換爲文件對象
我使用的代碼如下: -
<input type="file" multiple onchange="ehDisplayFileNames(event);" />
function ehDisplayFileNames(event) {
myFilesList = $('#' + event.target.id)[0]; // $('#chooseFiles')[0] gives the DOM element of the HTML Element as opposed to $('#store-input') which gives the jQuery object
$("#FilesToUpload").val(JSON.stringify(filesToUpload));
}
function getAllFiles(){
var filesToUpload = [];
filesToUpload = $.parseJSON($("#FilesToUpload").val()); // returns json objects instead i need file objects
}
謝謝你的幫助。
什麼是文件對象?你的意思是JS對JSON字符串?如果是,請使用: var myObject = jQuery.parseJSON 這將是一個對象 –
輸入:文件對象 – user3328402
你知道https://developer.mozilla.org/en-US/docs/Web/API/FileReader嗎? – Bergi