javascript:第四章 NaN和 isNaN(二)

<!DOCTYPE HTML>html

<html>ide

<head>ui

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">spa

<title>无标题文档</title>htm

<script>ip

window.onload = function (){utf-8

var aInp = document.getElementsByTagName('input');文档

var str = '';字符串

aInp[1].onclick = function (){get

str = aInp[0].value;

// HTML 中拿到的内容,类型都是字符串

// alert( typeof str );


if( isNaN(str) ){

alert( str + '不是数字' );

}else{

alert( str + '是数字' );

}

};

};

</script>

</head>


<body>


<input type="text" />

<input type="button" value="判断输入值是否是数字" />


</body>

</html>

相关文章
相关标签/搜索