lean and mean
2017 年 6 月 26 日
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <body> <script> let $ = parent => (tagName, attr, fn) => { if(tagName){ let node = Object.assign(document.createElement(tagName), attr); fn && fn($(node)); (parent || document.body).appendChild(node); }else{ fn(parent); } }; let $E = ev => fn => p => p.addEventListener(ev, fn); let click = $E('click'); $()("div", {style: 'color: red;'}, $ => { $("ul", {style: 'text-decoration: underline;'}, $ => { for(let i = 0; i < 10; ++i){ $("li", {innerText: i}, $ => { $(null, null, click(_ => alert(i))) }); } }); }); </script> </body> |