
我正在使用jQuery。如何获取当前URL的路径并将其分配给变量?
示例网址:
http://localhost/menuname.de?foo=bar&number=0
要获得路径,您可以使用:
var pathname = window.location.pathname; // Returns path only
var url = window.location.href; // Returns full URL
纯jQuery风格:
$(location).attr('href');
位置对象还具有其他属性,如主机,散列,协议和路径名。
未经作者同意,本文严禁转载,违者必究!




近期评论