The correct source code is as follows:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var lastTime = 3;
Function abc (){
Var btnReg = document. getElementById ("btnReg ");
If (! BtnReg) {return ;}
If (lastTime <= 0 ){
BtnReg. value = "agree ";
BtnReg. disabled = "";
ClearInterval ("TimeId ");
}
Else {
BtnReg. value = "remaining" + lastTime + "second ";
LastTime --;
}
}
Var TimeId = setInterval ("abc ()", 1000 );
</Script>
I define var btnReg = document. getElementById ("btnReg") in the fourth line as the global variable btnReg = document. getElementById ("btnReg ");
Besides the function abc (), the program cannot implement the function.
The reason is as follows: the browser parses the Html page from top to bottom and parses it to btnReg = document. when getElementById ("btnReg") is used, the button whose id is btnReg has not been parsed. Therefore, the value of the global variable btnReg is defined,
Because the program is only executed once, the program cannot implement the function, and the correct source program is retrieved once every second. After the button is parsed, the program can go to the value, the program can implement the function.