URI.js - 处理URLs的JavaScript库

admin 12年前
     <p>URI.js是一个javascript库用于处理URLs地址。它提供了类似于jQuery风格的API(便利的接口和方法链)。</p>    <p>URI.js提供了简单,但强大的方式来处理查询字符串,URI的正常化功能和绝对与相对路径的转换。</p>    <h2>示例</h2>    <p>如何使用jQuery风格的URLs API。</p>    <pre class="brush:javascript; toolbar: true; auto-links: false;">// mutating URLs URI("http://example.org/foo.html?hello=world")     .username("rodneyrehm")          // -> http://rodneyrehm@example.org/foo.html?hello=world     .username("")          // -> http://example.org/foo.html?hello=world     .directory("bar")         // -> http://example.org/bar/foo.html?hello=world     .suffix("xml")             // -> http://example.org/bar/foo.xml?hello=world     .hash("hackernews")         // -> http://example.org/bar/foo.xml?hello=world#hackernews     .fragment("")         // -> http://example.org/bar/foo.xml?hello=world     .search("") // alias of .query()         // -> http://example.org/bar/foo.xml     .tld("com")         // -> http://example.com/bar/foo.xml     .search({ foo: "bar", hello: ["world", "mars"] });         // -> http://example.com/bar/foo.xml?foo=bar&hello=world&hello=mars</pre>    <p>如何处理字符串:</p>    <pre class="brush:javascript; toolbar: true; auto-links: false;">URI("?hello=world")     .addSearch("hello", "mars")         // -> ?hello=world&hello=mars     .addSearch({ foo: ["bar", "baz"] })         // -> ?hello=world&hello=mars&foo=bar&foo=baz     .removeSearch("hello", "mars")         // -> ?hello=world&foo=bar&foo=baz     .removeSearch("foo")         // -> ?hello=world</pre>    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1325215556202" target="_blank">http://www.open-open.com/lib/view/home/1325215556202</a></p>