The code is as follows:
document.getElementById("btnConnect"). value = "Connecting";
Connect(); // Time-consuming operation
document.getElementById("btnConnect").value = "Connected";
Execute I found that the button did not change to the "Connecting" state, but waited for Connect(); to finish executing before quickly changing it to "Connecting"
I was very depressed all afternoon. Later, my classmates helped and provided One method, plus setTimeout, achieves the desired effect.
The code is as follows
document.getElementById("btnConnect" ).value = "Connecting";
setTimeout("Connect()", 1);
Then document.getElementById("btnConnect").value = "Connected"; Moved to Connect().