如何在jQuery中更新(附加到)href? [英] How to update (append to) an href in jquery?

查看:101
本文介绍了如何在jQuery中更新(附加到)href?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接列表,所有链接都转到了Google Maps api.

I have a list of links that all go to a google maps api.

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

the links already have the daddr (destination) parameter in them as static. I am using Geo-Location to find the users position and I want to add the saddr (source address) to the links once I get the data.

所以基本上,我将需要在所有指向Google地图的链接的末尾添加&saddr=50.1234567,-50.03452之类的内容

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

All the links have a class called directions-link

,并来自此页面已经弄清楚如何更改它们:

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

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

但是,我只想将我的值附加到href的末尾,而无需更改href已经是什么.

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

我该怎么做?

推荐答案

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中更新(附加到)href?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆