## 事件優化
> * 使用事件代理
>
>
> * 當存在多個元素需要注冊事件時,在每個元素上綁定事件本身就會對性能有一定損耗。
> * 由于DOM Level2事件模 型中所有事件默認會傳播到上層文檔對象,可以借助這個機制在上層元素注冊一個統一事件對不同子元素進行相應處理。
>
> 捕獲型事件先發生。兩種事件流會觸發DOM中的所有對象,從document對象開始,也在document對象結束。
>
>
>
> ~~~
> <ul id="parent-list">
> <li id="post-1">Item 1
> <li id="post-2">Item 2
> <li id="post-3">Item 3
> <li id="post-4">Item 4
> <li id="post-5">Item 5
> <li id="post-6">Item 6
> </li></ul>
> // Get the element, add a click listener...
> document.getElementById("parent-list").addEventListener("click",function(e) {
> // e.target is the clicked element!
> // If it was a list item
> if(e.target && e.target.nodeName == "LI") {
> // List item found! Output the ID!
> console.log("List item ",e.target.id.replace("post-")," was clicked!");
> }
> });
> ~~~