问题
Possible Duplicate:
jQuery - is it bad to have multiple $(document).ready(function() {});
Can you have multiple $(document).ready(function() sections?
I would like to know if it's allowed to have multiple instances of:
$(document).ready(function(){
})
on one of several pages ?
回答1:
Yes. Not a problem to do that.
Just to extend on that: http://jsfiddle.net/CBCrZ/
回答2:
not sure what you mean by on several pages. But yes you can have multiples of document.ready. They will get called in the order you add them.
回答3:
Is fine to have more than one. The call order is the same as the definition order: first-come first-served.
See also here: second $(document).ready event jQuery
回答4:
Yes. You can use it more than once. see this post
http://docs.jquery.com/Tutorials:Multiple_$(document).ready()
来源:https://stackoverflow.com/questions/8743599/jquery-document-ready-multiple-allowed