Definition and Usage
|
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,指定字符串的进制类型 |
Note: Only the first number in the string is returned!
注意:只返回字符串的第一组连续数字
Note: Leading and trailing spaces are allowed.
注意:允许字符串包含空格
Note: If the first character cannot be converted to a number, parseInt() returns NaN.
注意:如果字符串的第一个字符不能被转换成数字,将返回NaN
In this example we will use parseInt() to parse different strings:
在下面的例子中,我们演示了如何用parseInt()方法来转换不同的字符串:
<script type="text/javascript"> document.write(parseInt("10") + "<br />") </script> |
The output of the code above will be:
输出结果为:
10 10 |
|
来自: 小庄 > 《javascript》