2010-08-07 46 views
0

我的HTML如下:jQuery的一類選擇鏈接包含文本

<span class="srch-URL"> 
<a id="CSR_U_2" href="http://www.test.com/TestForm.aspx">http://www.test.com/TestForm.aspx</a> 
</span> 

我試圖使用jQuery找到匹配類「-RCH-URL」,然後更改包含與之如果該鏈接的所有元素他們通過在鏈接上添加& Source =/default.aspx來結束TestForm.aspx。下面

了jQuery會檢查包含TestForm.aspx

$('a[href*="TestForm.aspx"]') 

所有鏈接,但我只需要對是否包含在類「-RCH-URL」這樣做,那麼追加&源參數...

回答

1

嘗試:

$('span.srch-URL a[href*="TestForm.aspx"]') 

如果你是如何更改URL不確定,請嘗試:

$('span.srch-URL a[href*="TestForm.aspx"]').each(function(){ 
    $(this).attr('href', $(this).attr('href') + '&Source=/default.aspx') 
}); 
+0

更改網址的效果很好,非常感謝,導航 – van 2010-08-07 16:04:02