Home > Web Front-end > JS Tutorial > javascript search method for parsing url_javascript skills

javascript search method for parsing url_javascript skills

WBOY
Release: 2016-05-16 18:34:44
Original
1677 people have browsed it
Copy code The code is as follows:

function searchParse(){
var resultObj = {};
var search = window.location.search;
if(search && search.length > 1){
var search = search.substring(1);
var items = search.split(' &');
for(var index = 0; index < items.length; index ){
if(! items[index]){
continue;
}
var kv = items[index].split('=');
resultObj[kv[0]] = typeof kv[1] === "undefined" ? "":kv[1];
}
}
return resultObj;
}
//Sample Code
//Url:http://localhost/default.aspx?a=hello&b=kt&c=group
var searchObj = searchParse ();
var a = searchObj["a"]; //a==hello
var b = searchObj["b"]; //b== kt
var c = searchObj[" c"]; //c== group

If the above code is not good enough, you can refer to the following article.
Javascript gets the url parameter and gets the url parameter function code in the script tag

JavaScript URL parameter reading improved version

javascript[js] code to get url parameters
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template