2012-04-26 12 views
1

このJavascriptコードでw3c検証エラーが発生しました。このJavascriptスニペットでW3C検証エラーが発生しました

// hide all element nodes within some parent element 
function hideAll(parent) { 
    var children = parent.childNodes, child; 
    // loop all the parent's children 
    for (var idx=0, len = children.length; idx<len; ++idx) { /* ERROR HERE */ 
     child = children.item(idx); 
     // if element node (not comment- or textnode) 
     if (child.nodeType===1) { 
      // hide it 
      child.style.display = 'none'; 
     } 
    } 
} 

エラーは以下のとおりです。

  • 要素 "LEN" 未定義
  • 文字 ";"属性指定リストで許可されていません

セミコロンidx<len;は間違っています。

誰かが上記のコードスニペットでどこが間違っているのか説明できますか?

多くのありがとうございます。

答えて

1

に変更し、それを:

// hide all element nodes within some parent element 
function hideAll(parent) { 
    var children = parent.childNodes, child; 
    // loop all the parent's children 
    var len = children.length; 
    for (var idx=0; idx<len; ++idx) { /* ERROR HERE */ 
     child = children.item(idx); 
     // if element node (not comment- or textnode) 
     if (child.nodeType===1) { 
      // hide it 
      child.style.display = 'none'; 
     } 
    } 
} 
+0

おかげで、リック。しかし、私はまだまったく同じ検証エラーを取得しています。 – michaelmcgurk

+0

バリデーションではセミコロンが強調表示されています:** idx michaelmcgurk

+1

別のブラウザを試すかキャッシュをクリアしてください – Mediator

1
  **// hide all element nodes within some parent element 



      function hideAll(parent) 
      { 
       var children = parent.childNodes, child; 

       // loop all the parent's children 
       var len=children.length; 

       for (var idx=0; idx<len; ++idx) 
       { /* ERROR HERE */ 

        child = children.item(idx); 

        // if element node (not comment- or textnode) 

        if (child.nodeType===1) 
        { 
         // hide it 
         child.style.display = 'none'; 
        } 
       } 
     }** 
関連する問題