我一直收到此错误,请帮助并感谢您的所有想法:
未捕获的TypeError:无法读取null的属性“removeChild” 在HTMLDivElement。
发生在:bigImage.parentNode.removeChild(bigImage); spinner.parentNode.removeChild(旋转器);
这是我的程序只需在每次点击时删除图像,直到只有1张图像,然后如果用户点击最后一张图像,它将显示全屏图像。
myArtlist.addEventListener("click", function (e) {
chooseArt(e);
}, false);
function chooseArt (event) {
if (event.target.tagName === "IMG") {
var numberOfImage = document.querySelectorAll("ul.grid li>img");
var countImage = numberOfImage.length;
console.log(numberOfImage);
console.log(countImage);
if (countImage > 1) {
var myImage = event.target.parentNode;
myImage.parentNode.removeChild(myImage);
}
if (countImage === 1) {
var overlay = document.querySelector("div.overlay");
overlay.style.display = "block";
var imageSrc = event.target.src;
var bigImage = document.createElement("img");
bigImage.className = "bgImg";
bigImage.src = imageSrc.substr(0,imageSrc.length-7) + ".jpg";
overlay.appendChild(bigImage);
var spinner = document.createElement("img");
spinner.className = "spinner";
spinner.src = "images/spinner.gif";
overlay.appendChild(spinner);
bigImage.addEventListener("load", function () {
overlay.removeChild(spinner);
}, false);
overlay.addEventListener("click", function () {
overlay.style.display = "none";
bigImage.parentNode.removeChild(bigImage);
spinner.parentNode.removeChild(spinner);
}, false);
}
}
}