<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
textarea {
display: block;
width: 800px;
height: 34px;
overflow: hidden;
padding: 5px 10px;
margin: 30px auto 0;
resize: none;
line-height: 24px;
font-size: 16px;
color: #666;
border: 1px solid #ccc;
outline: 0 none;
box-shadow: 0 0 5px #999;
border-radius: 3px;
box-sizing: border-box;
transition: all 200ms linear;
}
textarea:focus {
color: #277fe4;
border-color: #2196f3;
box-shadow: 0 0 5px #03a9f4;
}
.btn-area {
margin: 30px auto 0;
text-align: center;
}
.i {
text-align: center;
}
</style>
</head>
<body>
<div>
<p class="i">
<img id="codeImg" src="#" alt="Base64图片" />
</p>
<div class='btn-area'>
<input value="展示" type="button" onclick="show()" />
<input value="清理" type="button" onclick="clean()" />
</div>
<textarea placeholder="请输入base64图片数据" oninput="areaListen(this)" id="source" rows="1" cols="60" autofocus></textarea>
</div>
<script>
function show() {
$("codeImg").src="data:image/png;base64," + $("source").value.replace(/\\r\\n/g, '');
}
function clean() {
$("source").value = "";
console.log("清理完毕")
}
function areaListen(dom) {
dom.style.height = 'auto';
dom.style.height = dom.scrollHeight + "px";
$("codeImg").src="data:image/png;base64," + dom.value.replace(/\\r\\n/g, '');
}
function $(id) {
return document.getElementById(id);
}
</script>
</body>
</html>
base64图片示例
/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a\r\nHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy\r\nMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAoAFgDASIA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAA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