如何获取当前LIElement的id,它在activeNav()中触发事件e,因为我想从navMap中找到活动元素。
import 'dart:html';
Map navMap = new Map<String, LIElement>();
void main() {
navMap["#li-home"] = query("#li-home");
navMap["#li-about"] = query("#li-about");
navMap["#li-setting"] = query("#li-setting");
navMap["#li-home"].onClick.listen(activeNav);
navMap["#li-about"].onClick.listen(activeNav);
navMap["#li-setting"].onClick.listen(activeNav);
}
void activeNav(Event e){
// Get element #li-home from map and add class "active"
// remove the class "active" from remain LIElements in navMap
答案 0 :(得分:3)
您无需在地图中存储所有li
元素。只需将事件处理程序附加到包含ul
的{{1}},找出点击的li
,然后添加或删除“有效”类:
li