A piece of js code encountered a bug, which was caused by the implicit global variable in the middle.
Due to the large amount of code, I found the problem through the js debugger of Google Chrome.
By the way, my computer is equipped with I can’t use fiefox. I have tried many times since last year but all failed.
But Google’s debugging is also very useful.
The simplified code is as follows:
$(function() {
var pageNo = 2;//This parameter changes
var pageSize = 10;
test();
paginate(pageNo,pageSize);//Because the test() method overrides pageNo , causing pageNo to always be equal to 1
});
function test(){
pageNo = 1;//Global variable, overwriting the previous pageNo, equivalent to writing var pageNo = 1 at the top of js
//Change here to var pageNo = 1; that's it
//do,,,
}
function paginate(pageNo,pageSize){
window.location.href = "user_list.action ?pageNo=" pageNo "&pageSize=" pageSize;
}
In js, it is recommended that all variables be declared with var, and all variables can be written to the top, because js does not have blocks level scope.