动态创建树节点tree

xiaoxiao2021-02-28  134

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <a id="create" href="javascript:void(0)">创建列表</a> </body> </html> <script type="text/javascript"> var create = document.getElementById("create"); var ul = document.createElement("ol"); var num = 0; create.addEventListener("click",function () { tree(ul,{"width":100}) },false); function tree(obj,paramas) { if ( paramas == undefined) { return; }else { var li = document.createElement("li"); if (paramas.background !== undefined) { li.style.background = paramas.background.toString(); }else { li.style.background = "blue"; } if (paramas.width !== undefined) { li.style.width = parseFloat(paramas.width)+'px'; }else { li.style.width = 50+'px'; } obj.append(li); document.body.append(obj); } } </script>
转载请注明原文地址: https://www.6miu.com/read-17847.html

最新回复(0)