<img src="https://cdn131.picsart.com/271777618047201.jpg?r240x240"
crossorigin="anonymous" id="image" width="400">
想象一下,我有一个 HTML 标签,如下所示:
<img src="https://cdn131.picsart.com/271777618047201.jpg?r240x240"id="image" width="400">
我可以通过 const tag = document.getElementById('image');
获取图像元素。现在,我唯一的问题是,如何在将鼠标悬停在图像上时获得上面的 html 标记。
最佳答案
您可以使用 target
你的属性(property)event
对象:
document.querySelector('div').addEventListener('mouseover', e => {
console.log(e.target);
});
<div>hover me</div>
关于javascript - 如何在悬停时获取图像的整个 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51876871/