我有一个链接列表,所有链接都指向谷歌 map api.

链接中已经有daddr(目的地)参数作为静态.我使用地理位置来查找用户的位置,我想在获得数据后将saddr(源地址)添加到链接中.

so basically I will need to add something like &saddr=50.1234567,-50.03452 at the tail end of all the links pointing to google maps

所有链接都有一个名为directions-link的类

and from this page I have figured out how to change them:

$("a.directions-link").attr("href", "http://www.google.com/");

However I only want to append my value to the end of the href without changing what the href already is.

How can I do that?

推荐答案

var _href = $("a.directions-link").attr("href");
$("a.directions-link").attr("href", _href + '&saddr=50.1234567,-50.03452');

each()循环

$("a.directions-link").each(function() {
   var $this = $(this);       
   var _href = $this.attr("href"); 
   $this.attr("href", _href + '&saddr=50.1234567,-50.03452');
});

Jquery相关问答推荐

如何向父元素添加类?

jQuery单击/切换两个功能

jQuery $(document).ready () 触发两次

jQuery:获取所选单选按钮的父 tr

为什么我们在 jQuery 中使用({ })?

Google Maps API v3 infowindow 关闭事件/回调?

JQuery手风琴自动高度问题

在 jQuery 中将 JSON 数组转换为 HTML 表

Zepto 和 jQuery 2 有什么区别?

谷歌图表重绘/zoom 窗口调整大小

如何使用 jquery 更改 onclick 事件?

在 jquery 中启用/禁用下拉框

使用 JQuery 获取触发事件的元素的类

jQuery '如果 .change() 或 .keyup()'

在 jQuery UI 自动完成上没有检测到结果

用 Javascript 加载 jQuery 并使用 jQuery

jquery在加载时获取iframe内容的高度

在ajax请求中检测重定向?

单击时平滑滚动到特定的 div

如何在 jquery 中获取 textarea 的值?