0

当值未定义时,我试图跳过执行操作。

当我运行以下代码时,它会发出警报,例如,“第 114 行有未定义的对象用户”。这是运行 IE9 的机器上的 hta 文件。我尝试了各种检查未定义的方法,但不确定我做错了什么。检查 currentcell != null 不起作用。

 var currentcell;
    for(var i = new_promotion_startrow; i<new_employees_endrow;i++)
    {
    currentcell = sheet.Cells(i,21);
    if(currentcell != 'undefined' && currentcell != 'None')
    {
    alert('row ' + i + ' has ' + currentcell + ' ' + typeof(currentCell) + ' users.');
    }
    }
4

1 回答 1

0

您可以使用严格的比较运算符

if (currentcell !== undefined && currentcell !== null) {...}
于 2013-10-10T04:07:44.083 回答