【发布时间】:2013-12-24 16:47:50
【问题描述】:
在将图像上传到服务器之前,我使用以下代码在客户端预览图像,适用于 Chrome,但不适用于 Safari。为什么?
JavaScript。
$('#imageUpload').change(function(){
readImgUrlAndPreview(this);
function readImgUrlAndPreview(input){
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#imagePreview').attr('src', e.target.result);
}
};
reader.readAsDataURL(input.files[0]);
}
});
HTML。
<img src="" id="imagePreview" alt="Preview Image" width="40px" height="40" style="border:none !important; border-width:0px !important;"/>
<input type="file" name="imageUpload" id="imageUpload"/>
<label for="imageUpload" id="UploadImage1Label" >Upload image</label>
谢谢。
【问题讨论】:
标签: javascript jquery html safari cross-browser