码迷,mamicode.com
首页 > 编程语言 > 详细

javascript——base64

时间:2016-04-26 17:21:11      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<head>
<title>欢迎</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1">
<link rel="stylesheet" href="css/common.css">
</head>
<body>
<div class="main">
<input type="file" id="demoInput">
<textarea id="result" cols="30" rows="10"></textarea>
<div id="imgArea">
123
</div>
</div>
<script type="text/javascript">
window.onload = function(){
//var main = document.getElementsByClassName(‘main‘)[0];
var myFile = document.getElementById(‘demoInput‘);
var result = document.getElementById(‘result‘);
var imgArea = document.getElementById(‘imgArea‘);

if(typeof(FileReader)===‘undefined‘){
result.innerHTML = ‘请使用现代浏览器操作‘;	
}
else{
myFile.addEventListener(‘change‘,readFile,false);
}

function readFile(){
var file = this.files[0];
if(!/image\/\w+/.test(file.type)){
alert(‘请上传图片‘);
return false;
}

//debugger;
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(){
var img = document.createElement(‘img‘);
img.src = this.result; 
img.style.width = "100%";
img.style.height = "100%" ;
document.body.appendChild(img);
result.innerHTML = ‘<img src="‘+this.result+‘" />‘;
}
}

// myFile.onchange = function(){

// readFile();//返回方法结果

// }

//myFile.onchange = readFile;//方法签名

}
</script>
</body>
</html>

  

javascript——base64

标签:

原文地址:http://www.cnblogs.com/MonaSong/p/5435709.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!