获取指定元素的父元素。如果提供了选择器,它只在匹配该选择器时才检索父元素。
finder.parent(node, selector)
Example: 为无序列表 <ul class=“subnav”>的所有直接父元素加上边框。
<!DOCTYPE html> <html> <head> <style> body { font-size: 14px; } </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> <ul class="topnav"> <li class="child1">Item 1</li> <li class="child2">Item 2 <ul class="subnav"> <li>Nested item 1</li> <li>Nested item 2</li> <li>Nested item 3</li> </ul> </li> <li class="child3">Item 3</li> </ul> <script> require(["skylark/styler", "skylark/finder"], function(styler, finder) { styler.css(finder.parent(finder.find("ul.subnav"), ".child2"), "border", "3px double red"); }); </script> </body> </html>