2011-05-16 17 views
3

我想更改包含「foobar.com/?」的所有鏈接使用jquery廣告「& t = test」(「foobar.com/?& t = test」)。如何在jQuery中添加鏈接的HREF?

這是我的代碼,似乎沒有工作。 - >

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

我的代碼有什麼問題?或者什麼是更合適的方式來改變所有的鏈接?

回答

7

這是如何做到這一點

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