What's the difference between `on` and `live` or `bind`?

前端 未结 7 2051
迷失自我
迷失自我 2020-11-22 16:00

In jQuery v1.7 a new method, on was added. From the documentation:

‘The .on() method attaches event handlers to the currently se

7条回答
  •  执念已碎
    2020-11-22 16:34

    on is in nature very close to delegate. So why not use delegate? It's because on doesn't come alone. there's off, to unbind event and one to create an event to be executed one time only. This is a new event's "package".

    The main problem of live is that it attaches to "window", forcing a click event (or other event) on an element deep inside the page structure (the dom), to "bubble up" to the top of the page to find an event handler willing to deal with it. At each level, all event handlers have to be checked, this can add up fast, if you do deep imbrication (

    提交回复
    热议问题