输入base64码
显示图片
window.onload = function () {
var file_input = document.getElementById( "file_input" ),
result = document.getElementById( "result" ),
inputBase=document.getElementById( "inputBase" ),
showImg=document.getElementById( "showImg" );
function readFile() {
var file = this.files[0];
var reader = new FileReader();
reader.readAsDataURL( file );
reader.onload = function ( e ) {
result.innerHTML= this.result;
}
}
if ( typeof(FileReader) === 'undefined' ) {
result.innerHTML = "抱歉,你的浏览器不支持 FileReader,请使用现代浏览器操作!";
file_input.setAttribute( 'disabled', 'disabled' );
}
else {
file_input.addEventListener( 'change', readFile, false );
}
showImg.addEventListener( 'click', function(){
debugger;
document.querySelector("img" ).src=inputBase.value;
}, false );
};