获取指定元素的最近的祖先,选择一个选择器。
finder.ancestor(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; } fieldset { margin:1px; padding:3px; } </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" /> <fieldset> <label>Grandchild:</label> <input name="newsletter" /> </fieldset> </form> Sibling to form: <input name="none" /> <script> require(["skylark/finder", "skylark/styler"], function(finder, styler) { styler.css(finder.ancestor(finder.find("input "),"form"),"border", "2px dotted blue"); }); </script> </body> </html>