2.2.10 提问:谈谈 JavaScript 中的事件委托(Event Delegation)的概念和⽤法。
JavaScript事件委托是⼀种利⽤事件冒泡原理,将事件绑定在⽗元素上,通过事件冒泡将事件传播到⼦元素上的技术。通过事件委托,可以减少页⾯上事件处理函数的数量,提⾼性能。常见的⽤法是将事件绑定在⽗元素上,通过事件对象的target属性获取触发事件的⼦元素,从⽽实现针对⼦元素的操作。例如,给⼀个ul元素下的所有li元素添加点击事件处理函数,可以通过事件委托实现:});在这个⽰例中,点击ul下的任何li元素都会使其⽂字变为红⾊,⽽⽆需为每个li单独绑定事件处理函数。
10 Screens$8,029
I will design rough sketches for upto 5 Screens of your website/Mobile app.
3 Days
Delivery
1
Revision
- Source File
- Commercial Use
- Interactive Mockup
- 10 Pages
20 Screens$16,029
I will design rough sketches for upto 5 Screens of your website/Mobile app.
- Source File
- Commercial Use
- Interactive Mockup
- 10 Pages
30 Screens$24,029
I will design rough sketches for upto 5 Screens of your website/Mobile app.
- Source File
- Commercial Use
- Interactive Mockup
- 10 Pages