這可能是一個非常基本的問題,我試圖從輸入字段獲取圖像信息。從輸入字段獲取圖像信息
form.html -
<form id="file-form" action="handler.php" method="POST">
<input type="file" id="file-select" name="image" multiple/>
<input type="text" id="text-input" />
<button type="submit" id="upload-button">Upload</button>
</form>
而在我的js文件,我搜索輸入字段使用的ID。
upload.js -
var fileSelect = jQuery('#file-select');
我想找出爲什麼使用
var file = fileSelect[0].files
我能夠得到的文件信息,而這樣做
var file = fileSelect.files
回報「未定義「。但這樣做
jQuery('#text-input').val();
實際上返回值,即使我不包括任何索引值
感謝一大堆!
fileSelect是一個數組。使用console.log或在瀏覽器的調試控制檯中運行代碼以檢查其值。 – Clay