JavaScript Tutorial/Global/isNaN
Версия от 18:52, 25 мая 2010; (обсуждение)
Global.isNaN()
Syntax
isNaN(variable)
Use isNaN to check if the input is a number
<html>
<head>
<title>The NaN property of the Number object</title>
<script type="text/javascript" language="javascript">
<!-- //
function Calculate(){
var entry;
var number = new Number();
entry = prompt("Enter a number or string: ", "Enter number or string here");
number = Number(entry);
if (isNaN(number)){
document.writeln("<P>You entered: " + entry+ "</p>");
document.write("<P>It was not a number</p>");}
else{
document.writeln("<P>You entered: " + entry + "</p>");
document.write("<P>It was a number.</p>");
}
}
// -->
</script>
</head>
<body onload="Calculate()">
</body>
</html>