在我的代码中,我允许用户上传图像。现在我想在同一个弹出窗口中将所选图像显示为预览。我怎样才能使用 jQuery 做到这一点?
以下是我在弹出窗口中使用的输入类型。
HTML 代码:
<input type="file" name="uploadNewImage">
Demo http://jsfiddle.net/LvsYc/
HTML:
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
jQuery
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]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
参考 https://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)