2012-04-10 56 views
1

我有几个文本框,其中返回javascript Number值,如果有效的数据是在文本框中,否则NaN。我得到这种奇怪的行为。当我在firebug检查(这两个文本框为空白):Javascript variable /'NaN'behaviourirdirdly

>>> hours 
NaN 
>>> minutes 
NaN 
>>> minutes == NaN 
false 
>>> hours == NaN 
false 
>>> hours == minutes 
false 

为什么表现如此?

回答

3

NaN不等于任何东西,甚至不是NaN

Reference at MDN

​​

对于权威人士透露,看到ECMAScript 5 Official Specification,部分11.9.111.9.3

1. If Type(x) is the same as Type(y), then 
    [...] 
    c. If Type(x) is Number, then 
    i. If x is NaN, return false. 
    ii. If y is NaN, return false. 
     [...] 
+0

谢谢'isNaN'就做好了:) – 0xc0de 2012-04-10 08:23:28