上传图片,实时显示在页面中
html页面如下
<img id="blah1" src="" alt="" width="200px"class="img-thumbnail">
<input id="courseImgSmall" type="file" name="picture" />
js中如下:
function readURL1(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#blah1').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#courseImgSmall").change(function() {
readURL1(this);
});
实现效果如下: