尝试这样的事情。这是一个现场演示
$('a').each(function(){
var link = $(this).attr('href');
link = link.replace('www.mysite.com', 'www.othersite.com');
link = link.replace('mysite.com', 'http://www.externalsite.com');
$(this).attr('href', link)
});
由于您似乎有非常特定的链接要替换当前链接,因此您需要对其进行调整以处理所有特定更改。此示例简单处理域文本替换。从您提供的示例中很难收集特定的“规则”。
如果您只有少量链接,那么对替换进行硬编码可能会更好。
$('a').each(function(){
var link = $(this).attr('href');
var newLink = null;
if (link == 'http://www.mysite.com/link1')
newLink ='http://www.othersite.com/link';
else if (link == 'mysite.com/link2')
newLink ='www.externalsite.com/link-another';
if (newLink) $(this).attr('href', newLink)
});