This morning till now, I have been engaged in a very stupid problem and have not found it.
If $ str = "";
$ Str = "$ str-$ sno ";
In this case, there will be a space in front of $ str. After js obtains this value, it must remove the space.
Remove the space function rstr = rstr. replace (/(^ \ s *) | (\ s * $)/g ,"");
In addition:
Remove the left space replace (/(^ \ s *)/g ,"");
Remove the right space replace (/(\ s * $)/g ,"");
In addition, if you perform step-by-step verification of the program flow, stop at the if. Make sure to output the two values in the if for comparison, or add # To the front to check whether there is space.
To sum up
1. space may be generated when a string is used for connection. When the string is split, it may be different from the original one. Therefore, you must remove the leading and trailing spaces.
2. When obtaining data from the server, JS must pay attention to the possibility of Space occurrence.