What is the easiest way to read/manipulate query string params using javascript?

后端 未结 7 1884
余生分开走
余生分开走 2020-12-05 11:45

The examples I\'ve seen online seem much more complex than I expected (manually parsing &/?/= into pairs, using regular expressions, etc). We\'re using asp.net

7条回答
  •  时光取名叫无心
    2020-12-05 12:13

    For jQuery I suggest jQuery BBQ: Back Button & Query Library By "Cowboy" Ben Alman

    jQuery BBQ leverages the HTML5 hashchange event to allow simple, yet powerful bookmarkable #hash history. In addition, jQuery BBQ provides a full .deparam() method, along with both hash state management, and fragment / query string parse and merge utility methods.

    Example:

    // Parse URL, deserializing query string into an object.
    // http://www.example.com/foo.php?a=1&b=2&c=hello#test
    // search is set to ?a=1&b=2&c=hello
    // myObj is set to { a:"1", b:"2", c:"hello" }
    var search = window.location.search;
    var myObj = $.deparam.querystring( search );
    

提交回复
热议问题