admin管理员组文章数量:1432587
I'm getting a JS error because my $(function () {...})
handler is being fired seemingly before the prerequisite plugin script is loaded. Only happens in IE (testing in IE7).
I have some HTML in my <head>
that looks like this:
<script type="text/javascript" src="../resources/org.wicketstuff.jwicket.JQuery/jquery-1.4.2-special.js"></script>
...
<script type="text/javascript" id="noConflict"><!--/*--><![CDATA[/*><!--*/
jQuery.noConflict();
/*-->]]>*/</script>
...
<script type="text/javascript" src="../resources/.csc.aims.wicketponents.collapsiblefieldset.CollapsibleFieldsetBehavior/jquery.collapsiblefieldset.js"></script>
<link rel="stylesheet" type="text/css" href="../resources/.csc.aims.wicketponents.collapsiblefieldset.CollapsibleFieldsetBehavior/jquery.collapsiblefieldset.css" />
<script type="text/javascript">
jQuery(function(){
jQuery('#collapse119').collapse({"iconClosedUrl":"../resources/img/white_plus","iconOpenUrl":"../resources/img/white_minus"});
});
</script>
So notice the sequence, according to the HTML code, is as follows:
- jquery-1.4.2-special.js
- jQuery.noConflict() call
- jquery.collapsiblefieldset.js //defines $.fn.collapse
- jQuery('#collapse119').collapse(...) is called
When this code runs in FF, everything works fine. When I test it in IE7 (or IE8 w/Compat. View: IE7 standards mode), I get a javascript error. The debugger shows me that jQuery.fn.collapse is undefined.
Using the IE8 developer tools, I try to look at jquery.collapsiblefieldset.js. I see the script in the list, but the tool tells me that I can't set a breakpoint because the script isn't loaded.
Why does the collapsiblefieldset.js not get loaded before my $() ready handler is run? Any insight would be appreciated! Thanks.
I'm getting a JS error because my $(function () {...})
handler is being fired seemingly before the prerequisite plugin script is loaded. Only happens in IE (testing in IE7).
I have some HTML in my <head>
that looks like this:
<script type="text/javascript" src="../resources/org.wicketstuff.jwicket.JQuery/jquery-1.4.2-special.js"></script>
...
<script type="text/javascript" id="noConflict"><!--/*--><![CDATA[/*><!--*/
jQuery.noConflict();
/*-->]]>*/</script>
...
<script type="text/javascript" src="../resources/.csc.aims.wicket.ponents.collapsiblefieldset.CollapsibleFieldsetBehavior/jquery.collapsiblefieldset.js"></script>
<link rel="stylesheet" type="text/css" href="../resources/.csc.aims.wicket.ponents.collapsiblefieldset.CollapsibleFieldsetBehavior/jquery.collapsiblefieldset.css" />
<script type="text/javascript">
jQuery(function(){
jQuery('#collapse119').collapse({"iconClosedUrl":"../resources/img/white_plus","iconOpenUrl":"../resources/img/white_minus"});
});
</script>
So notice the sequence, according to the HTML code, is as follows:
- jquery-1.4.2-special.js
- jQuery.noConflict() call
- jquery.collapsiblefieldset.js //defines $.fn.collapse
- jQuery('#collapse119').collapse(...) is called
When this code runs in FF, everything works fine. When I test it in IE7 (or IE8 w/Compat. View: IE7 standards mode), I get a javascript error. The debugger shows me that jQuery.fn.collapse is undefined.
Using the IE8 developer tools, I try to look at jquery.collapsiblefieldset.js. I see the script in the list, but the tool tells me that I can't set a breakpoint because the script isn't loaded.
Why does the collapsiblefieldset.js not get loaded before my $() ready handler is run? Any insight would be appreciated! Thanks.
Share Improve this question asked Jun 5, 2010 at 0:37 RMorriseyRMorrisey 7,74911 gold badges58 silver badges75 bronze badges3 Answers
Reset to default 4You're using
$(function(){...});
which is synonym of
$(document).ready( function(){...} );
Instead, you might try
$(window).load( function(){...} );
which fires later in the page loading sequence.
Put all of your scripts at the bottom of the page, right before the </body>
tag.
If that doesn't fix it, move the scripts that do not appear to be loading in time back to the <head>
, and leave the rest of the scripts at the bottom.
To anyone else suffering from this problem, it might be worth double checking that you don't have multiple references to jQuery. If you have plugins defined in the head, then they will get overridden by a second jQuery call in the body.
本文标签: javascript(document)ready(function() ) runs before plugin script loadsStack Overflow
版权声明:本文标题:javascript - $(document).ready(function() {...}) runs before plugin script loads - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745604892a2665781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论