jQuery在底部加载时如何在HTML中使用jQuery? [英] How to use jQuery in HTML when jQuery loads at the bottom?

查看:97
本文介绍了jQuery在底部加载时如何在HTML中使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这个:

https://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-6-move-scripts-bottom-7200.html



但是可以想象一个MVC系统。您位于正文中,并尝试使用 $(document).ready 。它不会工作,因为jQuery没有加载。那么什么?

编辑:所以

 < body> 
这里我需要jQuery。但它不会工作,因为它没有加载。那么如何解决这个问题呢?
< / body>
< script src ='jquery>


解决方案

你似乎混淆了脚本声明的物理位置具有逻辑可用性。在jQuery加载后执行的任何脚本都可以使用jQuery,无论它是否由加载jQuery的标签在物理上看起来较高的标签加载。


according to this:

https://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-6-move-scripts-bottom-7200.html

but lets imagine an MVC system. You are inside the body, and try to use $(document).ready. It wont work since jQuery is not loaded. Then what?

EDIT: so

<body>
here I need jQuery. But it wont works since its not loaded. Then how to workaround this?
</body>
<script src='jquery>

解决方案

You seem to be confusing physical position of the script statement with logical availability. Any scripting that executes after jQuery is loaded has jQuery available, regardless of whether it is loaded by a tag that appears physically higher in the page than the tag that loads jQuery.

这篇关于jQuery在底部加载时如何在HTML中使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆