如何使用原型将链接更改为一段文本或某种非锚定元素 [英] How to change a link into a span of text or some kind of non-anchored element with prototype
本文介绍了如何使用原型将链接更改为一段文本或某种非锚定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个链接:
<a id="theLink" href="h***://stackoverflow.com">Go to SO</a>
如何使用原型去除 <a>
或只保留 innerHTML 使元素变为:
How can I use prototype to either strip <a>
's or just leave the innerHTML so that the elements becomes:
[h***://stackoverflow.com]
(不再可点击的东西)?
[h***://stackoverflow.com]
(something that is no longer clickable)?
Or maybe convert the <a>
to a <span>
推荐答案
试试这个
function removeAnchor() {
var link = document.getElementById('theLink');
var span = document.createElement("span");
var txt = link.href;
var textNode= document.createTextNode(txt);
span.appendChild(textNode);
link.parentNode.replaceChild(span, link);
}
这篇关于如何使用原型将链接更改为一段文本或某种非锚定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文