Home > Web Front-end > JS Tutorial > A small example of js getting or setting the url parameters of the current window_javascript skills

A small example of js getting or setting the url parameters of the current window_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:20:11
Original
1307 people have browsed it

Copy code The code is as follows:

// Get the value of the param parameter in the current window url
function get_param(param){
var query = location.search.substring(1).split('&');
for(var i=0;i var kv = query[i].split('=');
if(kv[0] == param){
return kv[1];
}
}
return null;
}

//Set the value of param in the current window url
function set_param(param,value){
var query = location.search.substring(1);
var p = new RegExp("( ^|&" param ")=[^&]*");
if(p.test(query)){
query = query.replace(p,"$1=" value);
location.search = '?' query;
}else{
}else{
             location.search = '?' query '&' param '=' value;
                                                                                         ? Content between the beginning and # (including? but not #).

In the previous page turning code, the above two functions were used



Copy code

The code is as follows:

var pre_page = parseInt(current_page) - 1;
set_param( 'page',pre_page);
}

//Next page
function page_next(current_page,page_total){
if(current_page < 1 || current_page >= page_total){
return false;
}
var next_page = parseInt(current_page) 1; set_param('page',next_page);

}


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
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template