遍历指定的节点及其子节点,在每个节点上执行回调函数。
noder.traverse(node,fun)
Example: 点击按钮 input 值增加。
<!DOCTYPE html> <html> <head> <style> </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> <button>traverse</button> <div> <input type="text" value=1 /> <input type="text" value=2 /> </div> <script> require(["skylark/query", "skylark/noder"], function($, noder) { $("button").on("click", function() { noder.traverse($("div")[0], function(node) { var selector = $(node), value = parseInt(selector.val()); if (value) selector.val(value + 1); }); }); }); </script> </body> </html>