html input上传的文件及后续处理,HTML Input FileUpload files用法及代码示例

HTML DOM中的Input FileUpload files属性用于返回FileList对象,该对象表示使用文件上载按钮选择的一个或多个文件,这是一个只读属性。通过FileList对象,您可以获得有关文件的信息。

用法:

fileuploadObject.files

例子:

Input FileUpload files Property

GeeksforGeeks

DOM Input FileUpload files Property

id="myFile"

multiple size="50"

οnchange="myFunction()">

function myFunction() {

var GFG =

document.getElementById("myFile");

var msg = "";

if ('files' in GFG) {

if (GFG.files.length == 0) {

msg =

"Select multiple files using" +

" 'Shift'.";

} else {

for (var i = 0; i < GFG.files.length; i++) {

msg += "" + (i + 1) +

". file
";

var file = GFG.files[i];

if ('name' in file) {

msg += "name:" + file.name + "
";

}

if ('size' in file) {

msg += "size:" + file.size +

" bytes
";

}

}

}

} else {

if (GFG.value == "") {

msg += "Select multiple" +

" files using 'Shift'.";

} else {

msg += "This file property" +

" is not supported!!";

/* If the browser does not

support the files property,

it will return the path of

the selected file instead. */

msg += "
The path of the " +

"selected file:" + GFG.value;

}

}

document.getElementById("demo").innerHTML = msg;

}

输出:

之前:

a6a7f52120469256e6364446223304a9.png

后:

a6a7f52120469256e6364446223304a9.png

支持的浏览器:

谷歌浏览器

Edge

火狐浏览器

Opera

Safari

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值