[英]Having Issue on Getting Uploaded File Name by jQuery
Can you please take a look at this demo and let me know why I am not able to get the name of the file(image) 能否请您看一下这个演示,让我知道为什么我无法获得文件名(图像)
$('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" />
As you can see I am getting undefined
in console. 如您所见,我在控制台中变得
undefined
。
$(this).prop("files")
returns a FileList
, not a single file. $(this).prop("files")
返回FileList
,而不是单个文件。
You'd need to do: 您需要执行以下操作:
$(this).prop("files")[0]['name']
See: https://developer.mozilla.org/en-US/docs/Web/API/FileList 请参阅: https : //developer.mozilla.org/en-US/docs/Web/API/FileList
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.