我試圖添加到包含特定文本的特定鏈接的末尾。將文本添加到包含某些東西的所有鏈接的結尾
在我的代碼中,我找到了特定的鏈接,並改變了它們的開頭,從原始鏈接留下一個變量。我需要添加到該變量的末尾。目前在我的代碼結尾我使用追加標籤,但它只增加了鏈接文本而不是實際的鏈接。我該怎麼做,或者有更好的方法?
$(document).ready(function() {
$("a[href^='http://www.1shoppingcart.com/']").each(function() {
this.href = this.href.replace(/^http:\/\/www\.1shoppingcart\.com\/SecureCart\/SecureCart.aspx/,
"http://www.1shoppingcart.com/SecureCart/Securecart.aspx/onclick = '_gaq.push(['_link', 'http://www.1shoppingcart.com/SecureCart/Securecart.aspx/");
});
$('a[href*=1shoppingcart]').append("']); return false;'");
});
我相信`this.href`是不安全的。我建議你使用jQuery的attr()來操作href屬性。 – 2011-01-06 21:17:01