苗火 Nicholas
[JS]How to read local file in JS
2017-1-22 萧


How to read local file in JS?


function jsReadFiles(files) {
if (files.length) {
var file = files[0];
var reader = new FileReader();
if (/text+/.test(file.type)){
reader.onload = function(){
$('body').append('<pre>' + this.result + '</pre>');
}
reader.readAsText(file);
}else if(/image+/.test(file.type)) {
reader.onload = function() {
$('body').append('<img src="' + this.result + '"/>');
}
reader.readAsDataURL(file);
}
}
}


 

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容