gpt4 book ai didi

javascript - 删除链接的 href 值的一部分

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

我有一些带有 href 属性的链接。

<a href="http://stackoverflow.com/...variable1.../">My Link</a>
<a href="http://stackoverflow.com/...variable2.../">My Link</a>
<a href="http://stackoverflow.com/...variable3.../">My Link</a>

我需要获取 href 值,删除 http://stackoverflow.com 并将链接转换为

<a href="/...variable1.../">My Link</a>
<a href="/...variable2.../">My Link</a>
<a href="/...variable3.../">My Link</a>

例如

$('a').each(function () {  

var full_link = $('a').attr('href') ;
var delete_part = 'http://stackoverflow.com' ;
var output = full_link - delete_part ;

$('a').attr('href',output);

});

那么你有什么建议吗?

最佳答案

给你:

$('a').each(function () {
$(this).prop('href', $(this).prop('href')
.replace(/^http:\/\/stackoverflow\.com/, ''));
});

希望这对您有所帮助。

关于javascript - 删除链接的 href 值的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31136972/

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