Rebinding events in jQuery after Ajax update (updatepanel)

后端 未结 9 2133
悲哀的现实
悲哀的现实 2020-11-27 10:15

I have several input and option elements on my page, each (well almost) have an event attached to update some text on the page once they change. I use jQuery which is really

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 10:45

    You could use jQuery and event delegation. Basically hook events to containers rather than every element and query the event.target and run script based on that.

    It has multiple benefits in that you reduce the code noise (no need to rebind). It is also easier on browser memory (less events bound in the DOM.)

    Quick example here.

    jQuery plugin for easy event delegation.

    P.S I am 99% sure delegation will be in the jQuery core at the next release.

提交回复
热议问题