开发者

loading jquery from code and use document.ready in the page

开发者 https://www.devze.com 2023-02-14 06:45 出处:网络
im trying to load the jquery from the code to prevent double loading of the jquery js file. Just curious how can I do that and still be able to use document.ready to perform operation after开发者_Go百

im trying to load the jquery from the code to prevent double loading of the jquery js file. Just curious how can I do that and still be able to use document.ready to perform operation after开发者_Go百科 document is loaded complete.

thanks


Just load jQuery with a <script> tag. Really.


You can use the HeadJS framework, which does this for you.


<script>
  !window.jQuery && (function() {
    alert("jQuery hasn't loaded");
  })();
</script>

Basically, write everything you want to do if jQuery hasn't loaded inside the anonymous function.

0

精彩评论

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