
原型 - childElements() 方法
收集元素的所有子元素,並將其返回為擴充套件元素的陣列。
索引 0 指元素最頂層的子元素。
語法
element.childElements();
返回值
HTML 元素的陣列。
示例
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function showElements() { var arr = $('father').childElements(); arr.each(function(node) { alert(node.nodeName + ': ' + node.innerHTML); }); } </script> </head> <body> <div id = "father"> <p id = "kid1">This is first paragraph</p> <p id = "kid2">This is second paragraph</p> </div> <br /> <input type = "button" value = "showElements" onclick = "showElements();"/> </body> </html>
輸出
prototype_element_object.htm
廣告