开发者

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

开发者 https://www.devze.com 2023-03-22 16:04 出处:网络
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.

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

精彩评论

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