Suppose you have a URL now, as follows.
Http://www.jb51.net
How to access to the ID and name inside the value of JS, to achieve our analysis of ideas.
First get the URL of the current page, through Window.location.href.
Extract the URL? The following section is through the slice () method.
Divides the fetched request object into an array of strings through the split () method.
Next look at the code.
function Geturlvars () {
var vars = [],
hash;
var hashes = Window.location.href.slice (Window.location.href.indexOf ('? ') + 1). Split (' & ');
for (var i = 0; i < hashes.length i++) {
hash = hashes[i].split (' = ');
Vars.push (Hash[0]);
Vars[hash[0]] = hash[1];
}
return vars;
}
The next step is to get the value of the specified parameter, as shown in the code.
var id = geturlvars () ["id"];
var name = Geturlvars () [' Name '];
Finally, let's look at jquery.
$.extend ({
geturlvars:function () {
var vars = [],
hash;
var hashes = Window.location.href.slice (Window.location.href.indexOf ('? ') + 1). Split (' & ');
for (var i = 0; i < hashes.length i++) {
hash = hashes[i].split (' = ');
Vars.push (Hash[0]);
Vars[hash[0]] = hash[1];
}
return vars;
},
geturlvar:function (name) {return
$.geturlvars () [name];
}
});
var id = $.geturlvar (' id ');
var name = $.geturlvar (' name ');
The above is a small series for everyone to use JavaScript to get the value of the parameters in request, the full content of the method, I hope to help you, a lot of support cloud Habitat Community ~