gpt4 book ai didi

javascript - 使用 HTML 和 Javascript 将所有 HTML 链接转换为另一个 URL

转载 作者:行者123 更新时间:2023-11-28 05:16:30 24 4
gpt4 key购买 nike

我正在尝试获取一个字符串中网站正文部分中的所有 HTML 链接,并将它们替换为另一个链接。

尝试过类似的方法但没有成功:

var search = "https://www.cloudflare.com/5xx-error-landing?utm_source=error_footer";
var replacement = "https://example.com/";

document.body.innerHTML = document.body.innerHTML.split(search).join(replacement)

https://www.cloudflare.com/5xx-error-landing?utm_source=error_footer”是我要替换的链接,“https://example.com/”是我要替换的链接。

最佳答案

这个怎么样:

$("[href='your link']").attr("href","new link");

关于javascript - 使用 HTML 和 Javascript 将所有 HTML 链接转换为另一个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45006555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com