我只想在argument[0].recordCount
大于零或未定义的情况下运行代码。但是,当argument[0].recordCound
警报显示未定义时,会运行代码。在JavaScript中未定义的测试
if(arguments[0].recordCount > 0 &&
arguments[0].recordCount !== 'undefined')
{ //if more than 0 records show in bar
document.getElementById('totalRecords').innerHTML =
arguments[0].recordCount + " Records";
}
我该如何测试未定义的?
+1。应该使用'!=='运算符来代替'!='? – stakx 2010-07-22 18:28:59
stakx:没有。'typeof'保证返回一个字符串,并且你将它的返回值与另一个字符串进行比较,所以无论你学到什么Crockfordian习惯,它都会很好。 – 2010-07-22 18:33:13
@stakx - 无关紧要。 'typeof'返回一个字符串。 – 2010-07-22 18:58:29