使用jQuery预加载网页 [英] Preload Webpage with jQuery

查看:67
本文介绍了使用jQuery预加载网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现以下脚本此处想知道是否可以使用相同的脚本预加载多个页面。原因是我想预加载一些将在fancybox中保存的表单,并且加载时间太长。使用此脚本可以更快地加载表单(它可以工作),但我不知道如何使它适用于多个页面。

I found the below script here but wanted to know if it is posible to preload multiple pages with the same script. The reason is I want to preload some forms that will be hold in fancybox and it takes too long to load. Using this script help load the form much faster (it works) but I don't know how to make it work for multiple pages.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
  jQuery().ready(function () {
    $.get('index2.html', function(data) {
     jQuery("#index2content").html(data);
    });
  });
</script>

<div id="index2content"></div>


推荐答案

此脚本加载页面index2.html和当DOM准备就绪时,将其内容放入div#index2content。

This script loads the page "index2.html" and puts its content into the div#index2content when the DOM is ready.

因此,如果要加载多个页面,可以执行以下操作:

So, if you want to load multiple pages, you can do the following:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
  jQuery().ready(function () {
    $.get('index2.html', function(data) {
     jQuery("#index2content").html(data);
    });

    $.get('index3.html', function(data) {
     jQuery("#index3content").html(data);
    });

    $.get('index4.html', function(data) {
     jQuery("#index4content").html(data);
    });
  });
</script>

<div id="index2content"></div>
<div id="index3content"></div>
<div id="index4content"></div>

这篇关于使用jQuery预加载网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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