简体   繁体   English

for循环if语句未输入

[英]for-loop if statement not entering

The point is to filter through the nodes of an array and find the paragraph. 重点是过滤数组的节点并找到段落。 The if statement is conditional tester is always false, hence never going in. But when I tested the node names using alerts, the 4th one is actually p. 如果条件测试器的if语句始终为false,则永远不会输入。但是当我使用警报测试节点名称时,第4个实际上是p。

//b is an array filled with 5 DOM Nodes one of which is a <p/>
for(var i=0;i<5;i++)
{   alert(b[i].nodeName);   //b[3].nodeName alerts p
    if(b[i].nodeName=="p")
    {
        //do something
        break;
    }
    else
    {
        continue;
    }
}

nodeName returns the tag name in uppercase (as does .tagName() ); nodeName以大写形式返回标签​​名称( .tagName() ); you're comparing it against lowercase. 您正在将其与小写字母进行比较。

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

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