jQuery difference between live() and ready()?

泄露秘密 提交于 2019-12-06 05:42:04

问题


What is the exact difference between live() and ready()?


Edit: found that die() is the opposite of live()


回答1:


.ready() lets you register a callback that fires when the DOM is ready - this is similar to using window.onload but fires earlier (and you can register more than one callback).

.live() lets you register a callback to a range of events based on a selector, which continually monitors the DOM and will register itself to new nodes that are added.




回答2:


live is used for attaching events to a current selector and all future matching selectors.

ready binds a function to be executed whenever the DOM is ready to be traversed and manipulated




回答3:


ready() fires once after the DOM has finished loading and is ready to be traversed and manipulated. Basically a replacement for the old trustworthy onload event on window (similar but not identical)

With live() you specify a selector and jQuery then attaches the function you specify as second argument to all elements matched now and in future (add to to DOM dynamically) for the event specified as first argument



来源:https://stackoverflow.com/questions/1772863/jquery-difference-between-live-and-ready

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!