javascript parseInt 方法

最近用js作了个日历,其中用到了parseInt方法,在月份转换中出了点问题,在此记录下:

比如 八月份 "08" 用parseInt("08") 得到的结果是 1;

搜了下parseInt的用法,才知道问题原因:

Definition and Usage
定义与用法

The parseInt() function parses a string and returns an integer.
parseInt()方法用于将一个字符串转换为整型数字。

The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.
进制参数用于指定目标字符串的进制类型。如:设定进制为16,目标字符串将从16进制先转为10进制再进行处理。

If the radix parameter is omitted, JavaScript assumes the following:
如果没有指定进制参数,JavaScript将依照下列规则进行:

  • If the string begins with "0x", the radix is 16 (hexadecimal)
    如果字符串以"0x"开始,视为16进制
  • If the string begins with "0", the radix is 8 (octal). This feature is deprecated
    如果字符串以"0"开始,视为8进制
  • If the string begins with any other value, the radix is 10 (decimal)
    其他的视为10进制

Syntax
语法

parseInt(string, radix)

Parameter
参数
Description
注释
string
字符串
Required. The string to be parsed
必选项。所要转换的字符串
radix
进制
Optional. A number (from 2 to 36) that represents the numeral system to be used
可选项。2到36,指定字符串的进制类型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值