1
我已经修改了功能如何在HTML上传之前预览图像?
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#upload").change(function() {
readURL(this);
});
</script>
,并包含在主体元素在我的形式此输入:
<input type="file" name="uploaded_files" id="upload"/>
<img id="blah" src="#" alt="your image" />
我也包括jQuery的:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
它的工作中的jsfiddle ,但它不在我的本地主机上工作。
http://stackoverflow.com/questions/18694437/how-to-preview-image-before-uploading-in-jquery – Tanatos