1、html 代码:
<div class="file-box">
<form action="upload.class.php" id="form_id" method="post" enctype="multipart/form-data" > <input type="file" name="imagename" id="imagename" οnblur="getimage(this)" /> <input type="button" class="btn" value="上传" οnclick="form_register();" /> </form> <img id="img_id" /> </div>
2、js代码
function getimage(obj)
{ var pic = obj.files[0]; var freader = new FileReader(); freader.readAsDataURL(pic); freader.onload = function(e) { document.getElementById('img_id').attr("src",e.target.result); }}