检查是否将文件加载到< input type =“文件">中. [英] check if a file is loaded to <input type="file">
本文介绍了检查是否将文件加载到< input type =“文件">中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有内容都在标题中:如何检查文件是否已加载到<input type="file">
?
Everything is in the title: how can I check if a file is loaded to <input type="file">
?
<input type="file" id="document-file" />
<input type="submit" id="document-send" />
<script type="text/javascript">
$('#document-send').click(function(event){
event.preventDefault();
var files = $("#document-file");
console.log(files.length);
}
</script>
files.length
总是返回我1
,即使未加载任何文件.
files.length
always returns me 1
even if no file is loaded.
推荐答案
您可以检查元素的files
属性,而不是jQuery对象:
You can check the files
property of the element, not the jQuery object:
var files = $("#document-file")[0].files;
这篇关于检查是否将文件加载到< input type =“文件">中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文