Home > Article > Web Front-end > jQuery plugin to get URL parameters_jquery
For example, your current URL is:
http://www.jb51.net/index.php?test=1&kk=2
If you want to get the test, you can introduce the plug-in and use
Get it as follows:
var test = $.query.get('test');
If the parameters have multiple identical names, you can do this:
var arr = $.query. get('testy');
Output: [Value 1, Value 2, Value 3...]
If you want to get one of multiple identical names, you can do this:
var arrayElement = $.query.get('testy[1]');
This plug-in can not only get parameters, but also set parameters.
Set a parameter:
var newUrl = $.query.set("section", 5).toString();
Output: "?section=5"
Set two parameters:
var newUrl = $.query.set("section", 5).set("action", "do").toString();
Output: "?action=do§ ion=5"
Remove a parameter:
var oldQueryAgain = $.query.REMOVE("type");
Empty all parameters:
var emptyQuery = $.query.empty();
Copy all parameters:
var stillTheSame = $.query.copy();
Plugin address:
http://plugins.jquery.com/project/query-object
javascript[js] Code to get url parameters
JavaScript URL Improved version of parameter reading