选择文件后尝试从输入字段访问文件属性。
尝试了此操作,但收到错误“文件未定义”
var file = $("#uploadedfile").prop("files")[0];
var fileName = file.fileName;
var fileSize = file.fileSize;
alert("Uploading: "+fileName+" @ "+fileSize+"bytes");
最佳答案
如果#uploadedfile
是类型为“file”的输入:
var file = $("#uploadedfile")[0].files[0];
var fileName = file.name;
var fileSize = file.size;
alert("Uploading: "+fileName+" @ "+fileSize+"bytes");
通常,这会在更改事件上触发,如下所示:
$("#uploadedfile").on("change", function(){
var file = this.files[0],
fileName = file.name,
fileSize = file.size;
alert("Uploading: "+fileName+" @ "+fileSize+"bytes");
CustomFileHandlingFunction(file);
});
FIDDLE
关于jquery - jQuery-文件属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8436315/