开发者

jQuery - Are there any negative effects for using multiple ready events?

I like to keep my relevant jQuery in included files. That way, when I need to work on a page, the relevant jQuery is at the top of the page.

Right now, I am including six files on a single page. That means there are six ready events being called when the page loads.

Are there any negative side effects for using the typical ready event in every included file?

<-- INCLUDED FILE AAAA --->
<script type="text/javascript">
$(document).ready(function() {
// SOME CODE HERE

});
</script>


<-- INCLUDED FILE BBBB --->
<script type="text/javascript">
$(document).ready(开发者_StackOverflowfunction() {
// SOME CODE HERE

});
</script>


<-- INCLUDED FILE CCCC --->
<script type="text/javascript">
$(document).ready(function() {
// SOME CODE HERE

});
</script>


you can use multiple ready events in your code without worrying about the performance

http://www.learningjquery.com/2006/09/multiple-document-ready

but keep in mind each ready event will be executed on its turn i.e. in the order they are defined or called


I don't know about any. It is an usual way how to use javascript plugins.

I just use it a different way:

(function ($) { $(function () {
       ....
}); })(jQuery);

but that's the same.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜