码迷,mamicode.com
首页 > 其他好文 > 详细

isNaN()实例

时间:2020-01-18 10:35:56      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:title   load   typeof   utf-8   type   实例   doc   body   字符   

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

isNaN()实例

标签:title   load   typeof   utf-8   type   实例   doc   body   字符   

原文地址:https://www.cnblogs.com/tongguilin/p/12208128.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!