W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>单击按钮可解析不同的字符串。</p> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var fNum1 = parseFloat("12345red"); //返回 12345 var fNum2 = parseFloat("0xA"); //返回 NaN, 部分浏览器实现会返回 0 var fNum3 = parseFloat("11.2"); //返回 11.2 var fNum4 = parseFloat("11.22.33"); //返回 11.22 var fNum5 = parseFloat("0102"); //返回 102 var fNum6 = parseFloat("red"); //返回 NaN document.getElementById("demo").innerHTML = fNum1 + "<br>" + fNum2 + "<br>" + fNum3 + "<br>" + fNum4 + "<br>" + fNum5 + "<br>" + fNum6 + "<br>" } </script> </body> </html>