不得不说,太孤陋寡闻了,上一篇jquery的$.ajax()利用FormData数据类型与php后台交互写到JavaScript没有特定函数获取文件名,现在要打脸了,看人家怎么说的:https://www.codexworld.com/how-to/get-file-info-name-size-type-javascript/
Before sending the file to the server for upload, it always a good idea to validate the file. Using JavaScript you can easily get the file info and validate in client-side. The following single line of javaScript code, help you to get the file name, size, type, and modified date
//DOM对象的FileUpload对象
var fileName = document.getElementById('file').files[0].name //文件名
var fileSize = document.getElementById('file').files[0].size //文件大小
var fileType = document.getElementById('file').files[0].type //文件类型
var fileModifiedDate = document.getElementById('file').files[0].lastModifiedDate //文件最近修改日期
本来一直都是直接使用jQuery来获取元素id的,所以上面那句话我想着下面这行jQuery代码来代替
var file = $("#file").files[0];//错误操作,为了演示用
但是我发现会报错,然后说是
DOM对象的方法jQuery对象是不能使用的。
然后找了大半天想知道jQuery对象和DOM对象的区别
DOM对象我觉得用以下的HTML DOM Tree来描述会好理解一下。