关于js中的Blob对象类型的详细介绍


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

var input = document.createElement("input");

input.type = "file";

input.accept = "image/*";

input.multiple = true;

input.style.display = "none";

document.body.appendChild(input);

 

var fileSelect = document.createElement("a");

fileSelect.href = "#";

fileSelect.appendChild(document.createTextNode("Choose files"));

document.body.appendChild(fileSelect);

 

var imgList = document.createElement("div");

imgList.innerHTML = "<p>No file Selected!</p>"

document.body.appendChild(imgList);

 

input.addEventListener("change", function(e) {

var files = this.files;

if(!files.length) {

return;

}

imgList.innerHTML = "";

var list = document.createElement("ul");

imgList.appendChild(list);

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

var li = document.createElement("li");

list.appendChild(li);

 

var img = document.createElement("img");

img.src = window.URL.createObjectURL(files[i]);

img.height = 60;

img.width = 60;

img.onload = function() {

window.URL.revokeObjectURL(this.src);

}

li.appendChild(img);

var info = document.createElement("span");

info.innerHTML = files[i].name + ":" + files[i].size + " bytes";

li.appendChild(info);

}

}, false);

 

fileSelect.addEventListener("click", function(e) {

input.click();

e.preventDefault();

}, false);

由于File对象继承自Blob,所以我们可以很方便的利用File对象加载本地系统图片文件,并通过createObjectURL生成一个URL并加以显示。

推荐教程:js教程

以上就是关于js中的Blob对象类型的详细介绍的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

js怎么添加css样式

js如何大小写转换?

js中substring、slice与substr的区别有哪些?

分享5种js字符串转数字的方法

实例汇总js call()及apply()的方法使用

js中隐藏元素用什么方法

js原型链是什么

html5+js绘制流星雨的示例代码分享

爬虫分析之 js逆向某验滑动加密(1)

h5和js有什么区别

更多相关阅读请进入《js》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...