源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>全局JavaScript 函数 parseInt()转换字符串为数字:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = parseInt("10") + "<br>" + parseInt("10.33") + "<br>" + parseInt("10 6") + "<br>" + parseInt("10 years") + "<br>" + parseInt("years 10"); </script> </body> </html>
运行结果