开发者

jQuery $(document).ready(): are multiple bindings to the document load event allowed?

does jquery support multiples of

$(document).ready(functio开发者_如何学Pythonn() {});

ie. can i make a few of these on the same page and they will all be executed? or does the newest one overwrite the last?


Yes you can bind multiple, you can bind as many as you want, like other event handlers, they'll execute in the order they were bound.

None will be overwritten, additionally if the document is already "ready", it'll execute immediately.

As a side note, there's also a shortcut version :)

$(function() {});

If you can combine them, of course do so, if you need your code to be modular and you need multiple ready handlers, that's okay too, just make sure that the order is correct if it matters, usually it's a non-issue in those cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜