2011-12-18 26 views
3

如何使用jquery添加一些地址到下面的鏈接值?像http://maps.google.com/maps?q=indianapolis使用jquery添加到鏈接的href值

<div class="driving-directions-link"> 
<a href="http://maps.google.com/maps?q=">Get Direction</a> 
</div> 
+0

你在哪裏得到的價值? – 2011-12-18 22:12:50

+0

有一個類的EventAddress的表格單元格,並從那裏的價值來傳遞到網址作爲查詢字符串..請幫助我在這裏.. – AJSwift 2011-12-18 22:18:28

回答

5
$("div.driving-directions-link > a").prop("href", function (index, oldHref) { 
    return oldHref + "indianapolis"; 
}); 

退房.prop,這可能需要一個函數,其中oldHref是很好,老href

例子:http://jsfiddle.net/c5VNK/

+0

我試過這個,它不工作.. – AJSwift 2011-12-18 22:26:51

+0

@AJSwift :我添加了一個適用於我的示例。你能檢查一下,看看你有什麼不同嗎? – 2011-12-18 22:30:34

+0

非常感謝您的先生!它的工作現在。非常讚賞! – AJSwift 2011-12-18 22:47:38

0

您可以更改整個URL,如果你想: $('a[href="http://maps.google.com/maps?q="]').attr('href', 'http://maps.google.com/maps?q=indianapolis');

http://jsfiddle.net/mGVQw/

+0

isn; t工作因某些原因。 – AJSwift 2011-12-18 22:26:26

+0

@AJSwift小提琴http://jsfiddle.net/mGVQw/ – henryaaron 2011-12-18 22:27:48