We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<!DOCTYPE html> <html> <head> <script src="http://common.cnblogs.com/script/jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { alert("加载完成!"); }); </script> </head> <body> <img src="http://mpic.tiankong.com/8a7/fc2/8a7fc22d9b75d8b9950e990d6d960da2/640.jpg@360h" /> </body> </html>
点评: 1、需要引用jquery 2、兼容所有浏览器。
方案2:<script>标签的async="async"属性 async的定义和用法(是HTML5的属性) async 属性规定一旦脚本可用,则会异步执行。 示例: <script type="text/javascript" src="xxxxxxx.js" async="async"></script> 点评: 1、HTML5中新增的属性,Chrome、FF、IE9&IE9+均支持(IE6~8不支持)。此外,这种方法不能保证脚本按顺序执行。 2、async 属性仅适用于外部脚本(只有在使用 src 属性时)。
<script type="text/javascript" src="xxxxxxx.js" async="async"></script>
方案3:<script>标签的defer="defer"属性 defer 属性规定是否对脚本执行进行延迟,直到页面加载为止。 有的 javascript 脚本 document.write 方法来创建当前的文档内容,其他脚本就不一定是了。 如果您的脚本不会改变文档的内容,可将 defer 属性加入到 <script> 标签中,以便加快处理文档的速度。因为浏览器知道它将能够安全地读取文档的剩余部分而不用执行脚本,它将推迟对脚本的解释,直到文档已经显示给用户为止。 示例:
<script type="text/javascript" defer="defer"> alert(document.getElementById("p1").firstChild.nodeValue); </script>
点评:兼容所有浏览器。此外,这种方法可以确保所有设置defer属性的脚本按顺序执行。
方案4:动态创建<script>标签 示例:
<!DOCTYPE html> <html> <head> <script type="text/javascript"> (function(){ var s = document.createElement('script'); s.type = 'text/javascript'; s.src = "http://code.jquery.com/jquery-1.7.2.min.js"; var tmp = document.getElementsByTagName('script')[0]; tmp.parentNode.insertBefore(s, tmp); })(); </script> </head> <body> <img src="http://mpic.tiankong.com/8a7/fc2/8a7fc22d9b75d8b9950e990d6d960da2/640.jpg@360h" /> </body> </html>
点评:兼容所有浏览器。 推荐使用第一个方案。
原文 http://www.cnblogs.com/huangcong/p/3747038.html
The text was updated successfully, but these errors were encountered:
No branches or pull requests
点评:
1、需要引用jquery
2、兼容所有浏览器。
方案2:<script>标签的async="async"属性
async的定义和用法(是HTML5的属性)
async 属性规定一旦脚本可用,则会异步执行。
示例:
<script type="text/javascript" src="xxxxxxx.js" async="async"></script>
点评:
1、HTML5中新增的属性,Chrome、FF、IE9&IE9+均支持(IE6~8不支持)。此外,这种方法不能保证脚本按顺序执行。
2、async 属性仅适用于外部脚本(只有在使用 src 属性时)。
方案3:<script>标签的defer="defer"属性
defer 属性规定是否对脚本执行进行延迟,直到页面加载为止。
有的 javascript 脚本 document.write 方法来创建当前的文档内容,其他脚本就不一定是了。
如果您的脚本不会改变文档的内容,可将 defer 属性加入到 <script> 标签中,以便加快处理文档的速度。因为浏览器知道它将能够安全地读取文档的剩余部分而不用执行脚本,它将推迟对脚本的解释,直到文档已经显示给用户为止。
示例:
点评:兼容所有浏览器。此外,这种方法可以确保所有设置defer属性的脚本按顺序执行。
方案4:动态创建<script>标签
示例:
点评:兼容所有浏览器。
推荐使用第一个方案。
原文 http://www.cnblogs.com/huangcong/p/3747038.html
The text was updated successfully, but these errors were encountered: