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

WBOY
Release: 2016-05-16 17:20:11
Original
1268 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);

}


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