有人能帮我理解为什么会这样吗?

时间:2021-11-13 22:44:47

I just run into the weirdest thing I've ever encounter.

我碰到了我遇到过的最奇怪的事情。

Consider this test page:

考虑这个测试页面:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script language=javascript>
        function test(myParameter) {
            alert(myParameter);
        }
    </script>
</head>
<body>
    <input type="button" value="Strange" onclick="javascript: test(044024);" />
    <input type="button" value="Ok" onclick="javascript: test('044024');" />
</body>
</html>

If I click the "strange" button, I get 18452, if I click the "ok" button I get 044024

如果我点击“奇怪”按钮,我得到18452,如果我点击“确定”按钮我得到044024

Does anyone know what is happening and explain it to me?

有谁知道发生了什么并向我解释?

3 个解决方案

#1


Javascript is interpreting the symbol 044024 as an octal value because of the leading 0.

由于前导0,Javascript将符号044024解释为八进制值。

044024 oct to dec is 18452

044024十月到十二月是18452

#2


Numbers prefixed with 0 are considered to be in octal (base 8)

前缀为0的数字被认为是八进制(基数为8)

#3


When you write a number with 0 as its first digit, it's an octal number.

当你写一个0为第一个数字的数字时,它是一个八进制数。

#1


Javascript is interpreting the symbol 044024 as an octal value because of the leading 0.

由于前导0,Javascript将符号044024解释为八进制值。

044024 oct to dec is 18452

044024十月到十二月是18452

#2


Numbers prefixed with 0 are considered to be in octal (base 8)

前缀为0的数字被认为是八进制(基数为8)

#3


When you write a number with 0 as its first digit, it's an octal number.

当你写一个0为第一个数字的数字时,它是一个八进制数。