javascript jquery url 构建器/解析器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4344405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery url builder/parser
提问by xpepermint
I'm searching for a jquery plugin for full URL manipulation (parsing, building).
我正在寻找用于完整 URL 操作(解析、构建)的 jquery 插件。
Example:
例子:
var url = 'http://mypage.com/?param=1'
var params = $.getParams(url) # {param: 1}
var newUrl = $.newUrl(url, {param:2}) # 'http://mypage.com/?param=2'
Thx.
谢谢。
采纳答案by meo
There is this jquery plugin https://github.com/allmarkedup/jQuery-URL-Parserthat I used once. But once you console.logwindow.locationyou will see that it is not so hard to do it your self.
我曾经使用过这个 jquery 插件https://github.com/allmarkedup/jQuery-URL-Parser。但是一旦你console.logwindow.location会发现自己做这件事并不难。
I never tried this one: http://urldecoderonline.com/javascript-url-decode-jquery-plugin.htmbut it seems it can build URL to.
我从未尝试过这个:http: //urldecoderonline.com/javascript-url-decode-jquery-plugin.htm但它似乎可以构建 URL。
Have fun
玩得开心
回答by Maksym Kozlenko
To convert a JavaScript object into a URL parameter string you can use the jQuery parammethod:
要将 JavaScript 对象转换为 URL 参数字符串,您可以使用 jQueryparam方法:
$.param({a:1, b:"Test 1"}) // gets: "a=1&b=Test+1"
To parse a URL parameter string into a JavaScript object use this solution.
要将 URL 参数字符串解析为 JavaScript 对象,请使用此解决方案。

