jQuery bind efficiency

前端 未结 4 869
说谎
说谎 2021-02-01 22:01

I\'m having issue with load speed using multiple jQuery binds on a couple thousands elements and inputs, is there a more efficient way of doing this?

The site has the

4条回答
  •  死守一世寂寞
    2021-02-01 22:55

    First, use the profiler built into Firebug to check where most of the delay is; just hit "profile", run your slow action, hit it again and see which calls are the most expensive.

    Second, look at "live" event handling: http://api.jquery.com/live/

    The way this works is that there's just one event handler, looking at the whole document, delegating to live event handlers. This works much faster when you have loads of elements, because you don't need to add an event handler to each element specifically.

提交回复
热议问题