Today, a bugger appears in the program. After debugging for a long time, the problem was discovered.
I did an experiment:
Alert (parseInt ("01"), when the value in this is 01 = 07, it is normal, but in "08 ", "09" will return 0
(This phenomenon occurs in ie kernel browsers, such as 360 browsers.) (Google and Firefox are not affected)
.
Check the information to find out the reasons for this phenomenon:
Explanation:
01--07 is normal, but and 08 are unqualified octal form, so it is processed as 0. To solve this problem, we can use another parameter of the parseInt function to tell parseInt to be processed in decimal format.
ParseInt ("08", 10) or parseInt ("09", 10)
ParseInt (string,
Radix) is used to convert a string to an integer. The second parameter is used to set the string format. Commonly used parameters include 2, 8, 10,
16 indicates the number of hexadecimal strings.
The value range of radix is 2 ~ 36. If it is not in this range, NaN is returned.
If the value of radix is set to 0 or not, the string format is automatically recognized:
Starting with "0x", parseInt () treats the rest of string except 0x as a hexadecimal number,
Starting with "0", parseInt () treats the characters except 0 in string as octal or hexadecimal numbers,
Take 1 ~ Starting with a number of 9, parseInt () treats it as a decimal number.
Pay attention to it in js later !!!