js代码:
//头像上传预览 $("#up").change(function() { var $file = $(this); var fileObj = $file[0]; var windowURL = window.URL || window.webkitURL; var dataURL; var $img = $("#ImgPr"); if(fileObj && fileObj.files && fileObj.files[0]){ dataURL = windowURL.createObjectURL(fileObj.files[0]); $img.attr(‘src‘,dataURL); }else{ dataURL = $file.val(); var imgObj = document.getElementById("ImgPr"); imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)"; imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL; } });
html:
<div class="picbtn"><img id="ImgPr" src="images/neik.png"</div> <a class="chooseimg" href="#"><input type="file" id="up">从手机相册中选择</a>
时间: 2024-10-10 17:43:23