首页 > 解决方案 > 剥离除以 http 开头的所有标签

问题描述

标签: htmlregex

解决方案


您可以删除所有不包含当前主机的标签:

const links = Array.from(document.getElementsByTagName('a'))
links.forEach(elm => {
  !elm.href.includes(window.location.host) && elm.parentNode.removeChild(elm);
})
<a href="https://google.com">google</a>
<a href="/about">about</a>

不需要 JQuery


推荐阅读