【发布时间】:2018-02-14 13:45:30
【问题描述】:
我想要当前的 url 路径及其查询字符串。
我在下面尝试过,但没有得到想要的输出。
var pathname = window.location.pathname; // Returns path only
var url = window.location.href;
假设我的网址是http://localhost:1111/Contact/Index?text=aa。
注意:这里查询字符串是可选的,如果没有查询字符串,那么它应该只提供路径名。
我想要 /Contact/Index?text=aa,TIA。
【问题讨论】:
-
我得到了答案它的 window.location.pathname+window.location.search.substr(1);
-
感谢大家的努力和时间..
-
window.location.search会为你做这件事。
标签: javascript jquery