首页 > 其他 > 详细

使用URI获取链接和参数

时间:2017-09-14 20:57:46      阅读:436      评论:0      收藏:0      [点我收藏+]

https://medialize.github.io/URI.js/docs.html#accessors-hostname 

这个是参考文档的地址

var uri = new URI("http://example.org/foo/hello.html?foo=bar&bar=baz");
// get search
uri.search(); // returns string "?foo=bar&bar=baz" (leading ?)
// get query
uri.query(); // returns string "foo=bar&bar=baz" (no leading ?)

// .query() and .search() behave the same for the following:

// set search
uri.search("?foo=bar&bar=baz"); // returns the URI instance for chaining
uri.search("foo=bar&bar=baz"); // returns the URI instance for chaining
// uri == "http://example.org/bar/world.html?foo=bar&bar=baz"

// remove query
uri.search(""); // returns the URI instance for chaining
// uri == "http://example.org/bar/world.html"

// get data map:
uri.search(true); // returns { foo: "bar", hello : ["world", "mars"] }

// set data map:
uri.search({ foo: "bar", hello : ["world", "mars"] });
// uri == "http://example.org/bar/world.html?foo=bar&hello=world&hello=mars"

// overwrite data through callback
uri.search(function(data) {
  return { hello : "world" };
});
// uri == "http://example.org/bar/world.html?hello=world"

// augment data through callback
uri.search(function(data) {
  data.foo = "bar";
});
// uri == "http://example.org/bar/world.html?hello=world&foo=bar"

// CAUTION: beware of arrays, the following are not quite the same
// If you‘re dealing with PHP, you probably want the latter…
uri.search("?foo=bar&bar=baz");
uri.search("?foo=bar[]&bar[]=baz");

使用URI获取链接和参数

原文:http://www.cnblogs.com/kangjy/p/7522455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!