目录

ancestors()

功能

获取指定元素的祖先,(可选) 选择器。

语法

finder.ancestors(node, selector)

参数

范例

Example: 查找input上的表单元素。

<!DOCTYPE html>
<html>

<head>
    <style>
  body { font-size:14px; }
  form { border:2px green solid; padding:2px; margin:0;background:#efe; }
  div { color:red; }
    </style>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script>
    <script>
    require.config({
        baseUrl: "./",
        packages: [
            { name: "skylark", location: "../../../src/skylark" },
        ]
    });
    </script>
</head>

<body>
  <form>
    <div>Form is surrounded by the green outline</div>
    <label>Child:</label>
    <input name="name" />
  </form>
   Sibling to form: <input name="none" />
    <script>
    require(["skylark/finder", "skylark/styler"], function(finder, styler) {
        finder.ancestors(finder.find("input "),"form").forEach(function(node, index) {
            styler.css(node, "border", "2px dotted blue");
        });
    });
    </script>
</body>

</html>