我正在制作一款打地鼠的游戏,要想在洞里制造一只鼹鼠,我需要一张图片.我找到了该图像,并使用JavaScript插入了该图像.在下面的代码中,我在另一个文件中执行了该操作,在该文件中我正在try 查看哪一种方法可以正常工作:
<div class="hole" id="h1"></div>
<script>
let mole = `<img src="mole.jpg" height="70px" width="70px" class="mole">`;
let moleNode = document.querySelector('.mole');
document.querySelector('#h1').innerHTML = mole;
document.querySelector('#h1').removeChild(moleNode); // Error: moleNode is not of type node.
// I also tried:
mole.parentNode.removeChild(moleNode); // Same thing as above. Also I thought it wouldn't work because there were 36 holes and I don't actually know how to do it then.
</script>