【发布时间】:2021-02-15 19:30:39
【问题描述】:
jslint 告诉 Unexpected 'for'。 所以我认为我必须用 foreach 转换 但如何? 如果有人可以帮忙 谢谢
// Grab the original element
var original = document.getElementsByTagName("noscript")[0];
// Create a replacement tag of the desired type
var replacement = document.createElement("span");
var i;
// Grab all of the original's attributes, and pass them to the replacement
for(i = 0, l = original.attributes.length; i < l; ++i){
var nodeName = original.attributes.item(i).nodeName;
var nodeValue = original.attributes.item(i).nodeValue;
replacement.setAttribute(nodeName, nodeValue);
}
// Persist contents
replacement.innerHTML = original.innerHTML;
// Switch!
original.parentNode.replaceChild(replacement, original);
【问题讨论】:
-
下面的答案对你有用吗?
-
如果您的问题是关于特定代码的,请确保包含语言标签以帮助分类/识别问题。