zoukankan      html  css  js  c++  java
  • jQuery.isNumeric() 和 js isNaN()

    jQuery.isNumeric( value )

    Description: 判断指定参数是否是一个数字值(字符串形式的数字也符合条件),返回 true 或者 false。

    Example:

     1 $.isNumeric( "-10" );     // true
     2 $.isNumeric( 16 );        // true
     3 $.isNumeric( 0xFF );      // true
     4 $.isNumeric( "0xFF" );    // true
     5 $.isNumeric( "8e5" );     // true (exponential notation string)
     6 $.isNumeric( 3.1415 );    // true
     7 $.isNumeric( +10 );       // true
     8 $.isNumeric( 0144 );      // true (octal integer literal)
     9 $.isNumeric( "" );        // false
    10 $.isNumeric({});          // false (empty object)
    11 $.isNumeric( NaN );       // false
    12 $.isNumeric( null );      // false
    13 $.isNumeric( true );      // false
    14 $.isNumeric( Infinity );  // false
    15 $.isNumeric( undefined ); // false

    JavaScript isNaN( value )

    Description: 检查其参数是否是非数字值,返回 true 或者 false。

    Example:

     1 isNaN(NaN);              // true
     2 isNaN(undefined);        // true
     3 isNaN(null);             // false 能转成0
     4 isNaN("");               // false 能转成0
     5 isNaN([]);               // false 能转成0
     6 isNaN({});               // true
     7 isNaN(new Object());     // true
     8 isNaN(new String());     // false
     9 isNaN(new String("a"));  // true
    10 isNaN(new Array());      // false 能转成0
    11 isNaN(new Date());       // false 能转成数字
    12 isNaN(new Date().toString());  // true
    13 isNaN(true);             // false 能转成1
    14 isNaN(0/0);              // true

    Notice:

      isNaN() 函数通常用于检测 parseFloat() 和 parseInt() 的结果,以判断它们表示的是否是合法的数字。

      isFinite() 函数用于检查其参数是否是无穷大。与 isNaN() 相反。

       

  • 相关阅读:
    [LeetCode] 374. Guess Number Higher or Lower
    [LeetCode] 35. Search Insert Position
    [LeetCode] 205. Isomorphic Strings
    [LeetCode] 87. Scramble String
    [LeetCode] 274. H-Index
    [LeetCode] 507. Perfect Number
    [LeetCode] 88. Merge Sorted Array
    [LeetCode] 283. Move Zeroes
    [LeetCode] 287. Find the Duplicate Number
    [LeetCode] 204. Count Primes
  • 原文地址:https://www.cnblogs.com/hzj680539/p/5033763.html
Copyright © 2011-2022 走看看