[英]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.