Using live() - benefits - similar to bind()

前端 未结 3 1697
攒了一身酷
攒了一身酷 2020-12-15 11:07

I have been doing some reading up on jquery live event and am still kind of confused? What is the benefit to using it?

http://docs.jquery.com/Events/live

I k

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 11:30

    Basically, with .live() you don't have to bother updating event handlers if you have a very dynamic web site.

    $('.hello').live('click', function () {
      alert('Hello!');
    });
    

    That example will bind the click event to any elements which already have the "hello" class as well as any elements that are dynamically inserted, be it by AJAX or by old-fashion JavaScript.

提交回复
热议问题