[英]Having Issue on Getting Uploaded File Name by jQuery
能否請您看一下這個演示,讓我知道為什么我無法獲得文件名(圖像)
$('input:file').on('change', function(){ console.log($(this).prop("files")['name']); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="file" name="file" id="test" />
如您所見,我在控制台中變得undefined
。
$(this).prop("files")
返回FileList
,而不是單個文件。
您需要執行以下操作:
$(this).prop("files")[0]['name']
請參閱: https : //developer.mozilla.org/en-US/docs/Web/API/FileList
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.