获取指定元素的最近的兄弟姐妹,可以提供一个可选的选择器。
finder.nextSiblings(elm, selector)
Example: 查找每个含有 “selected” 样式的 p 的所有兄弟元素。
<!DOCTYPE html> <html> <head> <style> li { margin: 3px; padding: 3px; background: #EEEEEE; } li.hilight { background: yellow; } </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> <p>Hello</p> <p>Hello Again</p> <p class="selected">And Again</p> <p class="selected">Agin And Again</p> <script> require(["skylark/styler", "skylark/finder"], function(styler, finder) { finder.nextSiblings(finder.find("p"), ".selected").forEach(function(node, index) { styler.css(node, "background", index % 2 === 0 ? "yellow" : "green"); }); }); </script> </body> </html>