如何使用jQuery添加链接的HREF?

3

我希望能够使用jquery更改所有包含“foobar.com /?”的链接,将其改为“& t = test”(“foobar.com /?& t = test”)。

这是我的代码似乎无法正常工作。->

$('a[href*="foobar.com/?"]').attr(href).append('&t=test');

我的代码有什么问题?或者改变所有链接的更恰当方式是什么?
1个回答

7

这是如何做到的

$('a[href*="foobar.com/?"]').each(function(){
  this.href += '&t=test';
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接