Possible Duplicate:
Comparing NaN values for equality in Javascript
Can anyone tell me why this is not working?
if(inbperr == NaN){
document.getElementById('inbclo').value = "N/A";
}
else{
document.getElementById('inbclo').value = "%" + inbperr;
}
Instead of returning a percentage value or "N/A" like I want it to it's returning "%NaN".
NaN
's are unusual: they are not equal to anything, even themselves. You need to use isNaN(inbperr)
to tell whether a value is a NaN or not.
NaN is Not a Number. One of few JavaScript toxic types. It can reduce whole expression to NaN.
来源:https://stackoverflow.com/questions/11354373/how-do-i-test-for-nan