<script type="text/javascript">
function ProcessFile(e){
var file= document.getElementById('file').files[0];if(!/image\/\w+/.test(file.type)){file= NaN
alert("看清楚,这个需要图片!");}{#document.getElementById("result").removeChild( document.getElementsByTagName("img")[0] );#}if(file){
var reader = new FileReader();
reader.onload = function (event){
var txt = event.target.result;
var img = document.createElement("img");
img.src = txt;//将图片base64字符串赋值给img的src
// console.log(txt);
img.width =540;
var div = document.getElementById("result");
div.innerHTML ="";
div.appendChild(img);};}
reader.readAsDataURL(file);}
function contentLoaded(){
document.getElementById('file').addEventListener('change',
ProcessFile, false);}
window.addEventListener("DOMContentLoaded", contentLoaded, false);</script>
完整代码:<script type="text/javascript"> function ProcessFile(e) { var file = document.getElementById('file').files[0]; if (!/image\/\w+/.test(file.type)) { file = N...