我的phonegap移动应用程序中有一个"File"类型的输入标签.我只选择该标签中的图像.现在我的问题是我们如何在同一个HTML中显示所选图像,如果用户选择图像,图像应该在HTML中显示.可能吗?
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); });
所选图像应显示在"selectedImage"Div中.可能吗?请给我任何建议
试试这个方法
在seleced div中添加图像
<img id="preview" src="#" alt="your image" />
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); });
DEMO