javascript循环

1 var element = document.getElementById("myList");

2 for (var i = 0, len = element.childNodes.length; i < len; i++) {

3     if (element.childNodes[i].nodeType == 1) {

4         console.log(element.childNodes[i].innerHTML);

5     }

6 }
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 2 <html xmlns="http://www.w3.org/1999/xhtml">

 3 <head>

 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

 5     <title></title>

 6 </head>

 7 <body>

 8     <ul id="myList">

 9         <li>Item 1</li>

10         <li>Item 2</li>

11         <li>Item 3</li>

12     </ul>

13     <script type="text/javascript" src="test34.js"></script>

14 </body>

15 </html>

你可能感兴趣的:(JavaScript)