【问题标题】:How to get the exact href value only without their domain?如何仅在没有域的情况下获得确切的 href 值?
【发布时间】:2013-01-21 04:44:47
【问题描述】:

我无法仅获取 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/

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

【问题讨论】:

标签: jquery


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 2020-05-12
      相关资源
      最近更新 更多