长这个样子
<div class="headL"></div>
用到window.URL.revokeObjectURL和window.URL.createObjectURL;
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "图片URL", true);
xhr.responseType = "blob";
xhr.onload = function () {
var blob = this.response;
var img = document.createElement("img");
img.onload = function (e) {
window.URL.revokeObjectURL(img.src);
};
img.src = window.URL.createObjectURL(blob);
$(".headL").html(img);
}
xhr.send();
</script>
这段代码展示了如何通过XMLHttpRequest获取图片的Blob数据,并利用window.URL.createObjectURL将Blob转换为URL,加载到img元素中显示。在图片加载完成后,通过window.URL.revokeObjectURL释放内存。
1018





