当前位置:嗨网首页>书籍在线阅读

29-解决方案

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

17.7.2 解决方案

用户根据他们在屏幕上看到的东西来感觉加载的时间。当浏览器加载外部内容(如JavaScript、CSS样式表和图片)时可以使用的HTTP连接有限。当JavaScript放在文档的开头时,就会推迟其他可见资源的加载。解决方案是将JavaScript文件放在页面的最后:

<!DOCTYPE html>
<html><head>
   <title>17.7 Putting JavaScript at the End of a Page</title>
</head>
<body>
   <h1>17.7 Putting JavaScript at the End of a Page</h1>
   <p>Lorem ipsum dolor...</p>
   <script src="../../jquery-1.3.2.min.js"></script>
   <script type="text/javascript">
     jQuery(document).ready(function() {
        jQuery('p').after('<p>Ut ac dui ipsum...</p>').show();
     });
   </script>
</body></html>