2012-04-26 4 views
1

이 자바 스크립트 코드로 인해 w3c 유효성 검사 오류가 발생하고 친절한 신사/아가씨가 잠시 나마 걸릴 수 있을지 궁금해합니다.W3C Validation errors with this javascript snippet

// 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'; 
        } 
       } 
     }**