<asp:FileUpload ID="FileUpload1" runat="server" onchange="chgImg(this)" /> <div> <img src="" id="Photo" runat="server" style="max-height: 80px;float:left" /> <div id="preview"></div> </div>
前台控件以及代码
function chgImg(file) { //img控件预览图片 //var FileUpload1 = $("#FileUpload1").val(); //div预览图片(兼容模式) $("#ContentPlaceHolder1_Photo").attr("src", ""); var prevDiv = document.getElementById(‘preview‘); if (file.files && file.files[0]) { var reader = new FileReader(); reader.onload = function (evt) { prevDiv.innerHTML = ‘<img src="‘ + evt.target.result + ‘" style="max-height:80px;" />‘; } reader.readAsDataURL(file.files[0]); } else { prevDiv.innerHTML = ‘<div class="img" style="max-height:80px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\‘‘ + file.value + ‘\‘)"></div>‘; } }
原文地址:https://www.cnblogs.com/daimaozidejiamao/p/8458124.html
时间: 2024-10-21 13:45:56