http://googl..." />

Javascript-如何删除链接中的链接

| 假设一个字符串包含“ 0”。当我链接整个字符串时(该字符串同时具有未链接的URL和已链接的URL,如上图所示),它将变为
<a href=\"<a \"\" href=\"http://google.com\"\">http://google.com\"</a>>http://google.com</a>
。 有没有办法将不正确的链接(链接之前已经链接过的链接)还原回“ 0”? 我在WordPress中发现它使用
$ret = preg_replace(\"#(]+?>|>))]+?>([^>]+?)#i\", \"$1$3\", $ret);
(在wp-includes / formatting.php中)来完成此任务。有人可以帮我用JavaScript做到这一点吗?     
已邀请:
看看这个http://jsfiddle.net/mplungjan/V5Qca/
<script>
function linkify(id,URL) {
  var container = document.getElementById(id);
  var links = container.getElementsByTagName(\"a\");
  if (links.length ==0) {
    container.innerHTML=container.innerHTML.link(URL);
    return;
  }
  var nodes = container.childNodes;
  for (var i=nodes.length-1;i>=0;--i) {
    if (nodes[i].nodeType ==3 && nodes[i].parentNode.nodeName!=\"A\") {
      var link = document.createElement(\"a\");
      link.href=URL;
      link.innerHTML=nodes[i].nodeValue;
      container.replaceChild(link, nodes[i]);
    }
  }
}
window.onload=function() {
  linkify(\"div1\",\"http://www.google.com/\");
}
</script>
<div id=\"div1\">
this is a <a href=\"test\">test</a> of replacing text with links with <a href=\"#\">linkified</a> content
</div>  
    

要回复问题请先登录注册