Prototype - recursivelyCollect() 方法

此方法以递归方式收集由属性指定关系的元素。属性必须是指向单个 DOM 节点的元素属性。

语法

element.recursivelyCollect(property);

属性值可以是以下任意值 −

  • parentNode
  • previousSibling
  • nextSibling

返回值

返回 HTML 元素数组。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var arr = $('fruits').recursivelyCollect('nextSibling');
            arr.each(function(node) {
               alert(node.nodeName + ': ' + node.innerHTML);
            });
         }
      </script>
   </head>

   <body>
      <p>单击按钮查看结果。</p>
      
      <ul id = "fruits">
         <li id = "apples">
            <ul id = "list-of-apples">
               <li id = "golden"><p>Golden</p></li>
               <li id = "mutsu">Mutsu</li>
               <li id = "mcintosh">McIntosh</li>
               <li id = "ida-red">Ida Red</li>
            </ul>
         </li>
      </ul>
      <p>This is the paragraph</p>
      <br />
      
      <input type = "button" value = "Show Result" onclick = "showResult();"/>
   </body>
</html>

输出

prototype_element_object.html