isNaN()实例

<!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;

扫描二维码关注公众号,回复: 8675952 查看本文章

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

        // alert( typeof str );

        if( isNaN(str) ){

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

        }else{

            alert( str + '是数字' );

        }

    };

};

</script>

</head>

<body>

<input type="text" />

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

</body>

</html>

猜你喜欢

转载自www.cnblogs.com/tongguilin/p/12208128.html
今日推荐