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>Click the button to see the result.</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.htm
广告