Copy codeThe Code is as follows:
// Obtain the param parameter value in the current window url
Function get_param (param ){
Var query = location. search. substring (1). split ('&');
For (var I = 0; I <query. length; I ++ ){
Var kv = query [I]. split ('= ');
If (kv [0] = param ){
Return kv [1];
}
}
Return null;
}
// Set the param value 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 {
If (query = ''){
Location. search = '? '+ Param +' = '+ value;
} Else {
Location. search = '? '+ Query +' & '+ param +' = '+ value;
}
}
}
Note: What is the url obtained by location. search? Content (including? But does not contain #).
In the previous Code, two functions are used.
Copy codeThe Code is as follows:
// Previous Page
Function page_pre (current_page, page_total ){
If (current_page <= 1 | current_page> page_total ){
Return false;
}
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 );
}