<html>
<head>
<script type="text/javascript" src="function.js"></script>

<script type="text/javascript">
        var x=123;
		var y="34";
		alert(x+y);
		alert(isNaN(y)); //
		if(!isNaN(y)){
		   alert(x+parseInt(y));
		}
</script>
</head>
<body>
   
</body>  
</html>

上面的代码isNaN的意思是is not a Number 也就是说当他是数字的时候返回的是false 当文本中含有数字的时候返回的true;

        var x=123;
		var y="casc234";
		alert(x+y);
		alert(isNaN(y)); //
		if(!isNaN(y)){
		   alert(x+parseInt(y));
		}

 返回的是true;

        var x=123;
		var y="casc234";
		alert(x+y);
		alert(isNaN(x)); //
		if(!isNaN(y)){
		   alert(x+parseInt(y));
		}

 返回的是false;

        var x=123;
		var y="casc";
		alert(x+y);
		alert(isNaN(y)); //
		if(!isNaN(y)){
		   alert(x+parseInt(y));
		}

 返回的是true;

说明这是判断一个这是不是一个字符串的方法,如果是字符串,则返回true;

如果不是字符串则返回false;

相关文章:

  • 2021-08-20
  • 2021-08-26
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
  • 2021-11-18
猜你喜欢
  • 2021-12-07
  • 2022-03-09
  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案