jquery Get URL Address
Jquery.fn.getparmbyurl = function (o) {
var url = window.location.tostring ();
var tmp;
if (URL && url.indexof ("?")) {
var arr = Url.split ("?");
var parms = arr[1];
if (parms && parms.indexof ("&")) {
var parmlist = Parms.split ("&");
Jquery.each (Parmlist,function (key,val) {
if (Val && val.indexof ("=")) {
var Parmarr = val.split ("=");
if (o) {
if (typeof (o) = = "string" && o = = Parmarr[0]) {
TMP = parmarr[1] = = null? ':p armarr[1];
}
}
else{
TMP = parms;
}
}
});
}
}
return TMP;
Application method
$ (function () {
$ (). Getparmbyurl () = = Null?window.location.href = '? id=100&class=4&sh=y&city= maoming &action ': ';
$ ("#btn"). Click (function () {
var a = $ (). Getparmbyurl ($ ("#key"). Val ());
alert (a);
});
});
Web effects get URL parameters and addresses
function getquerystring (name)
{
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");
var r = window.location.search.substr (1). Match (REG);
if (r!=null) return unescape (r[2]); return null;
}
The URL's parameter & parameter name 1=xxxx& parameter name 2=xxxx& parameter name 3=xxxx
Alert (getquerystring ("parameter name 1"));
Alert (getquerystring ("parameter Name 2"));
Alert (getquerystring ("parameter name 3"));
Detailed jquery get URL parameter description
Your current URL is:
http://www.xxx.com/index.php tutorial? test=1&kk=2
If you want to get test, you can introduce the plug-in,
Get it in the following ways:
var test = $.query.get (' test ');
If the parameter has multiple identical names, you can do this:
var arr = $.query.get (' testy ');
Output: [value 1, Value 2, value 3 ...]
If you want to get more than one of the same 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"
To delete a parameter:
var oldqueryagain = $.query.remove ("type");
Clear All Parameters:
var emptyquery = $.query.empty ();
Copy all parameters:
var stillthesame = $.query.copy ();
Plugin Address:
Http://plugins.jquery.com/project/query-object