gpt4 book ai didi

javascript - 链接检测并替换其他,在js中

转载 作者:行者123 更新时间:2023-11-30 13:35:41 25 4
gpt4 key购买 nike

你好 我想知道替换如何自动链接到我的网站开头为:

http://site.com/00000/

到:

http://site.com/11111/

检测>替换

最佳答案

CSS3 attribute "starts with" selectors在那里帮助你(jQuery 在它支持的所有浏览器上都支持它们——如果可能的话,使用原生功能,以提高速度)。然后只需使用 each 循环并更新原始 a 元素的 href 属性:

$("a[href^='http://site.com/00000/']").each(function() {
this.href = "http://site.com/11111/" + this.href.substring(21);
});

关于javascript - 链接检测并替换其他,在js中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4993264/

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