第一篇文章.测试专用
H5.文件的读取; 1.<input type="file" id="f1"> var f = document.getElementById("f1"); var length = f.files[0].size; var type = f.files[0].type; var html = "获得文件的长度是:"+length+"<br>"; html +="获得文件的类型是:"+type; if(type.indexOf("image/jpeg")>=0){ html+="<br>是一张图片" }else{ html+="<br>不是一张图片" } document.getElementById("div1").innerHTML = html; 2.function getFileText(){ var f = document.getElementById("f2").files[0]; var fr = new FileReader(); fr.readAsText(f,"utf-8"); fr.onload=function(e){ document.getElementById("div2").innerHTML=this.result;}} 3. var f = document.getElementById("f2").files[0]; var fr = new FileReader(); fr.readAsBinaryString(f); fr.onload=function(e){ document.getElementById("div2").innerHTML=this.result; 4. var f = document.getElementById("f2").files[0]; var fr = new FileReader(); fr.readAsDataURL(f); fr.onload = function(e){ document.getElementById("div2").innerHTML = "<img src="+this.result+"></img> "
H5.文件的读取;
1.<input
type="file" id="f1">
var f =
document.getElementById("f1");
var
length = f.files[0].size;
var
type = f.files[0].type;
var
html = "获得文件的长度是:"+length+"<br>";
html
+="获得文件的类型是:"+type;
if(type.indexOf("image/jpeg")>=0){
html+="<br>是一张图片"
}else{
html+="<br>不是一张图片"
}
document.getElementById("div1").innerHTML
= html;
2.function getFileText(){
var
f = document.getElementById("f2").files[0];
var fr = new FileReader();
fr.readAsText(f,"utf-8");
fr.onload=function(e){
document.getElementById("div2").innerHTML=this.result;}}
3.var f =
document.getElementById("f2").files[0];
var fr = new FileReader();
fr.readAsBinaryString(f);
fr.onload=function(e){
document.getElementById("div2").innerHTML=this.result;
4.var f = document.getElementById("f2").files[0];
var fr = new FileReader();
fr.readAsDataURL(f);
fr.onload = function(e){
document.getElementById("div2").innerHTML
= "<img src="+this.result+"></img> "