Prototype – 元素对象 recursivelyCollect() 方法

返回到:Prototype – 元素对象

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

语法

element.recursivelyCollect(property);

财产的价值可以是以下任何一项 –

  • parentNode
  • previous兄弟姐妹
  • 下一个兄弟姐妹

返回值

返回一个 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 – 元素对象

作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9045.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年2月8日
下一篇 2023年2月8日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注