[问题] get NodeList index

楼主: shiningboy   2016-09-26 13:45:22
想请问各位版友
如果有一个容器 div#container,底下有 4 个 children
也就是 nodeList 里面有 index = 0 , 1 , 2 , 3 的子元素
然后在 container 加上 click 的 EventListener 之后
请问有没有方法可以得到 被 click 的 子元素的 index??
也就是说 例如:我如果 click 第二个子元素 可以 get 1
再拜托各位解惑了
谢谢
作者: dododavid006 (朔雪)   2016-09-26 15:30:00
用 bind 或 closure 就行了吧
作者: jhunkyoiori (瓦尔加布)   2016-09-27 12:11:00
楼主: shiningboy   2016-09-28 00:32:00
没错 就是要 return index 楼上谢谢

Links booklink

Contact Us: admin [ a t ] ucptt.com