<input type="file" onchange="showImg(this,'img')" accept="image/*" />
<img id="img" style="width:100%;height: 100%;padding:1px;" src="null"/>
<script type="text/javascript">
//上传图片后立即预览 file对象,图片容器id
function showImg(fileObj, imgId) {
var file = fileObj.files[0];
var r = new FileReader();
r.readAsDataURL(file);
$(r).load(function () {
$('#' + imgId).attr("src", this.result);
})
}
</script>
js单个图片上传预览
猜你喜欢
转载自blog.csdn.net/q1923408717/article/details/114626854
今日推荐
周排行