我希望能够在上传之前预览文件(图像).预览操作应该在浏览器中全部执行,而不使用Ajax上传图像.
我怎样才能做到这一点?
我的phonegap移动应用程序中有一个"File"类型的输入标签.我只选择该标签中的图像.现在我的问题是我们如何在同一个HTML中显示所选图像,如果用户选择图像,图像应该在HTML中显示.可能吗?
<input type="file" id="fileUploader" />
<img id="preview" src="#" alt="your image" />
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
function readIMG(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#preview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#fileUploader").change(function(){
readIMG(this);
});
Run Code Online (Sandbox Code Playgroud)
所选图像应显示在"selectedImage"Div中.可能吗?请给我任何建议