<!DOCTYPE HTML>

<html>

<head>

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

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

<script>

window.onload = function (){

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

var str = '';

aInp[1].onclick = function (){

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>