Const list=document. The createElement method (" ul ");
For (const data of listData) {
Const li=document. The createElement method (" li ");
Const a=document. The createElement method (' a ');
Anderson nnerText=data. The name;
A.s etAttribute (' href 'data. The url);
Li. The appendChild (a);
Let hasChild=false;
If (data. Lists) {
HasChild=true;
Li. The appendChild (createList (data. Lists));
}
Li. SetAttribute (' class ', 'treenode + (hasChild? '- expandable' : '));
List. The appendChild (li);
}
return list;
}
Event handling:
CodePudding user response:
The switch (event. Target. LocalName) {Case "ul" :
Const ulnode=node. QuerySelector (" ul ");
//the setAttribute used to set the attribute of the element, and the display is style within the object attribute
Ulnode. Style. The display=(ulnode. Style. The display==""? "None" : "");
break;
A case of "li" :
Const ul=node. QuerySelector (" ul ");
//the setAttribute used to set the attribute of the element, and the display is style within the object attribute
Ul. Style. The display=(ul. Style. The display==""? "None" : "");
break;
Case "a" :
//the preventDefault default behavior method is used to block elements (click on a tag will default to the anchor link)
//event. The preventDefault ();
//the console. The log (event. The view. The location. Href);
//return;
break;
}