W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>如果值为 NaN(非数字),则 isNaN() 函数返回 true,否则返回 false。</p> <p>请单击按钮检查数字是否为非法数字。</p> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var res = ""; res = res + isNaN(123) + ": 123<br>"; res = res + isNaN(-1.23) + ": -1.23<br>"; res = res + isNaN(5-2) + ": 5-2<br>"; res = res + isNaN(0) + ": 0<br>"; res = res + isNaN('123') + ": '123'<br>"; res = res + isNaN('Hello') + ": 'Hello'<br>"; res = res + isNaN('2005/12/12') + ": '2005/12/12'<br>"; res = res + isNaN('') + ": ''<br>"; res = res + isNaN(true) + ": true<br>"; res = res + isNaN(undefined) + ": undefined<br>"; res = res + isNaN('NaN') + ": 'NaN'<br>"; res = res + isNaN(NaN) + ": NaN<br>"; res = res + isNaN(0 / 0) + ": 0 / 0<br>"; res = res + isNaN(null) + ": null<br>"; document.getElementById("demo").innerHTML = res; } </script> </body> </html>