该parseInt()
函数接受两个参数,一个是代表数字的字符串,另一个是代表基数的数字,并返回给定基数的整数。
它的语法如下
num.parseInt('4524', 8);
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var result = parseInt('4524', 8); document.write("Result: " + result); </script> </body> </html>
输出结果
Result: 2388
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var result1 = parseInt('4524', 8); document.write("Result: " + result1); document.write("<br>"); var result2 = parseInt('4524', 10); document.write("Result: " + result2); document.write("<br>"); var result3 = parseInt('4524', 16); document.write("Result: " + result3); </script> </body> </html>
输出结果
Result: 2388 Result: 4524 Result: 17700