html - 剥离除以 http 开头的所有标签
问题描述
解决方案
您可以删除所有不包含当前主机的标签:
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
推荐阅读
- r - 如何使用 dplyr 计算 R 中数据框列中的重复次数?
- visual-studio-code - VS Code 用文件打开扩展主机
- arrays - “TypeError:在 JSON 上循环时无法读取未定义的属性‘名称’”
- linux - 我想在文件 config.xml 中使用 sed 或 awk 命令添加 3 行
- ruby-on-rails - 多态关联轨道的相反方向
- python - 在 Python 中的 Jupyter Notebook 中显示决策树的巨大问题:ExecutableNotFound?
- java - sc.hasNextLine() 的无限循环
- docker - 无法使用 Cloudera 快速入门 VM 访问 http://localhost:7180
- c# - VSTO Aplication.Factory 类的接口实现缺少方法
- gradle - 带有 VSCode 的 Minecraft Forge Gradle