jQuery bind() unbind() and on() and off()

后端 未结 3 867
夕颜
夕颜 2021-02-10 05:05

Im working on a small adminarea for a webpage.

Does it make sense to unbind events for increasing performance(client)? Or does it cost more performance to unbind events

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-10 06:07

    One solution to avoid having to worry about this, especially if you deal with constantly changing elements or large quantities, is to register your event with the body and then specify a selector argument.

    Like this:

    $("body").on("click", ".my-actual-element", function(aEvent) {
       // Event handler code goes here.
    });
    

    See more here $.on().

提交回复
热议问题