gpt4 book ai didi

JQuery - 文件属性

转载 作者:行者123 更新时间:2023-12-03 21:41:29 25 4
gpt4 key购买 nike

选择文件后尝试从输入字段访问文件属性。尝试过此操作,但收到错误“文件未定义”

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 - 文件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8436315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com