<div id="par">
<span id="a1"></span>
<span id="a2"></span>
<div id="par2">
<span id="a3"></span>
<span id="a4"></span>
</div>
</div>
<script>
var ele = document.querySelectorAll('#par span');
for(var p of ele){
console.log(p);
}
</script>
3
A
답변
8
변환 가능한 형태로 만들려면 NodeList
에서 Array
으로 변환하십시오. 변환하려면 Array.from()
을 사용하십시오.
<div id="par">
<span id="a1"></span>
<span id="a2"></span>
<div id="par2">
<span id="a3"></span>
<span id="a4"></span>
</div>
</div>
<script>
var ele = document.querySelectorAll('#par span');
for (var p of Array.from(ele)) {
console.log(p);
}
</script>
더 많은 정보를 원하시면 다음과 같은 질문을 참조 :이 알고 Are HTMLCollection and NodeList iterables?
+0
고맙습니다. – zloctb
+0
@zloctb : 기꺼이 도와 드리겠습니다. :) –
관련 문제
- 1. PGT 및 PGTIOUs 저장 CAS 생성
- 2. 어떻게</p> <p>어떻게이 문제를 해결하기 위해 ........ 사용자 정의 테이블 형식
- 3. Javascript : Uncaught TypeError : undefined is not function
- 4. Uncaught TypeError : undefined is not function
- 5. 호이스트가 작동하지 않습니까? 이 프로그램에서 오류가</p> <blockquote> <p>Uncaught TypeError: fn2 is not a function</p> </blockquote> <p>있습니까 :
- 6. 출력 a = ~ a + 2 << 1;
- 7. Ext.application : Uncaught TypeError : undefined is not function
- 8. Uncaught TypeError : undefined is not function
- 9. 하한선 <A <상한선
- 10. 어떻게이 정규식이 작동하지 않습니까?</p> <pre><code>"<a\b[^>]*href=\"\\lyrics\\*\">(.*?)</a>"; </code></pre> <p>그리고 나는이 paremeters에서 값을 찾기 위해 노력하고있어 :
- 11. <a title="<a>">
- 12. <a href=' '> not working properly
- 13. 순회 내가 <a href="https://babeljs.io/docs/usage/polyfill/" rel="nofollow">babel-polyfill</a>을 사용하고 있는데 내가 루프의를 위해 사용 <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection" rel="nofollow"><code>HTMLCollection</code></a> 개체를 반복하기 위해 노력하고있어 대한-의 루프
- 14. Heredoc <<< 또는 <<?
- 15. <<< EOT
- 16. github add <<<<<<< HEAD
- 17. 수입 javax.xml.xpath의는</p> <p>1.5 내가 어떻게이 문제를 해결할 수 있습니다 안드로이드
- 18. 내가 JQuery와이</p> <pre><code><a href="https://github.com/someshwara/MultiDraggable"> multidraggable plug-in</a> </code></pre> <p>를 사용하기 위해 노력하고있어 addclass
- 19. 내가 피난처 때문에 오류</p> <pre><code>Uncaught ReferenceError: jQuery is not defined </code></pre> <p>다음 한의 젠토 커뮤니티
- 20. 보기 그룹을 확장하면 자식이 0이됩니까? 내가 getChildCount()를 호출</p> <p>내가 0 어떻게이 문제를 해결하기 위해 수 (가 XML에서보기를로드 한 후)
- 21. 파이썬 3.5 :</p> <pre><code>pool = multiprocessing.Pool(5) NameError: name 'multiprocessing' is not defined </code></pre> <p>그래서, 어떻게 그것을 해결하기 위해 :
- 22. git "<<<<<< HEAD"
- 23. 연산자 << : std :: cout << i << (i << 1);
- 24. 바보 같은 질문에 대한 <li><a></a></li>
- 25. 추가] 내용 <li><a></a></li>
- 26. 셀레늄 : "<div><a></a></div>"버튼을 클릭하십시오.
- 27. <a></a> 자동 참조 페이지 URL 내부 <a></a> 태그
- 28. <a name="..."> is obsolete, what is preferred?
- 29. 비동기 폭포 최종 콜백있어 기능은 내가 <code>cb is not a function</code>했다 가지고
- 30. 어떻게 단어 <ul><li><div><a></a></div></li></ul>
/... – zloctb
는 @Rajesh : 아니, 당신은 그들을 위해 in'에 대한'사용할 수 없습니다 – Bergi
@Bergi 네 말이 맞아. 내 사과. – Rajesh