[英]JavaScript OR Operator correct, but if statement not behaving as expected
我正在使用JavaScript繁重的应用程序,并且有以下代码:
function displayingNotes() {
if (!($scope.overseasTravelTask.RegisteredKeeperName.toLowerCase()
.indexOf("zenith") > -1 ||
$scope.overseasTravelTask.RegisteredKeeperAddressLine1.toLowerCase()
.indexOf("zenith")
)
)
{
$scope.calloutClass = 'callout-danger';
$scope.calloutMessage = 'We (Zenith) cannot provide this vehicle with the necessary documents.';
$scope.disableNextBtn = true;
}
else
{
$scope.calloutMessage = 'Please ask driver about this.';
}
}
对于if语句 ,我在Chrome控制台中放置了一个断点并检查了我的逻辑,并且逻辑看起来正确,但是当我单击F10按钮时,我希望进入if语句,而是跳过它!
||
的第二个操作数 是:
$scope.overseasTravelTask.RegisteredKeeperAddressLine1.toLowerCase().indexOf("zenith")
...这将产生一个数字:子字符串的索引;如果未找到,则为-1
。 因此,当强制转换为布尔值,这将是true
为小于当子发生在索引被发现其它所有情况下(-1,23,42,等等) 0
,在这种情况下,这将是false
。
您可能希望在其中添加!== -1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.