【问题标题】:qts on javascript, jquery [duplicate]javascript,jquery上的qts [重复]
【发布时间】:2011-08-14 09:41:09
【问题描述】:

可能重复:
Request Address in Javascript

有没有什么方法可以在 JavaScript 或 jquery 中检索当前页面的 URL?

请帮忙。

【问题讨论】:

  • 请为您的问题选择合适的标题。

标签: javascript jquery url


【解决方案1】:

window.location.href

这是你在 jQuery 中的做法:P

(function($) {
   $.getUrl = function() {
       return window.location.href;
   }
})(jQuery);

jsFiddle.

警告:显然 jQuery 函数是针对 LOL 的。不要真的使用它。

【讨论】:

  • @Blender 我加了一些:)
  • 做了一个矫枉过正的 jQuery 解决方案:$.getUrl()。该代码初始化函数。
【解决方案2】:

是的,使用location.href

alert(location.href)

【讨论】:

    【解决方案3】:

    使用下面的

    document.location.href

    【讨论】:

      【解决方案4】:

      使用

      document.location.href
      

      【讨论】:

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