如何在没有域名的情况下获得确切的href值?

时间:2013-02-06 04:10:53

标签: jquery

我在获取href的确切值方面遇到了麻烦。这是代码:

Link:
<a href="monthly"></a>

Script:
'a': function(target, process){
    if(process == "stripe"){
        document.location.href = "/accounts/stripe/payment"+target[0].href;
    }else{
        ......
    }
},

如果我运行此输出将是:

http://localhost:8000/accounts/stripe/paymenthttp://localhost:8000/monthly/

请注意,localhost正在重复。如何在没有本地主机的情况下只获得href中的“月度”?我只尝试目标,但它未定义。我尝试了目标[1],但它不起作用。

2 个答案:

答案 0 :(得分:9)

尝试target[0].getAttribute("href")获取文字属性的内容。

答案 1 :(得分:4)

一些鲜为人知的事实是,大多数浏览器也会将Anchor节点元素转换为Location对象。因此,您也可以访问位置可用的所有部分;

 document.location.href = "/accounts/stripe/payment"+target[0].pathname;
相关问题