【发布时间】:2021-01-29 12:30:01
【问题描述】:
我想在所有使用 Tampermonkey 的网站上用 img 标签替换所有 amp-img 标签。
我尝试了以下方法,但没有成功
var wns = document.getElementsByTagName("amp-img");
var lmn = document.createElement("img");
var index;
// Copy the children
while (amp-img.firstChild) {
img.appendChild(amp-img.firstChild); // *Moves* the child
}
// Copy the attributes
for (index = amp-img.attributes.length - 1; index >= 0; --index) {
img.attributes.setNamedItem(amp-img.attributes[index].cloneNode());
}
// Replace it
amp-img.parentNode.replaceChild(img, amp-img);
【问题讨论】:
-
amp-img怎么能成为js中的标识符呢? “破折号”导致语法错误
标签: html replace tampermonkey