我正在尝试使用 Chrome 扩展程序将一个按钮附加到网页上的每个图像。我的内容脚本中有以下代码:
var imagesArray = document.getElementsByTagName("img");
console.log(imagesArray);
for (const img of imagesArray) {
var button = document.createElement("button");
button.innerHTML = "button";
button.onclick = function() {
console.log("clicked");
}
img.append(button);
}
我能够获取所有图像,并且我知道我可以附加按钮,我只是不知道如何将按钮附加到图像上。任何帮助表示感谢
最佳答案
使用此行document.body.appendChild(button); <-- use this line
下来这个img.append(button)
关于javascript - Chrome 扩展程序向页面上的每个图像添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63141227/