繁体   English   中英

尝试检测HTA中的未定义-typeof返回对象

[英]Trying to detect undefined in hta - typeof returns object

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

当我运行以下代码时,它会发出警报,例如,“行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.');
    }
    }

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

if (currentcell !== undefined && currentcell !== null) {...}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM