jquery函数将html代码加载到一个div,然后加载其他内容到div里面加载html [英] jquery function that load html code into a div and then load other content into div inside html loaded

查看:131
本文介绍了jquery函数将html代码加载到一个div,然后加载其他内容到div里面加载html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将html网页(page1.html)加载到网页活动(index.html)的div中,然后将另一个html网页(page2.html)加载到div中在页面内加载(page1.html)。我是说。

I'd like to know what's the way to load an html page (page1.html) into a div in webpage active (index.html) and then load another html page (page2.html) into a div that will be inside of page loaded (page1.html). I mean.

index.html

index.html

<div id="content"></div>
<a class="link" href="#">load</a>

脚本

$(document).ready(function() {
    $('a.link').live('click', function() {
        $('#content').load('page1.html', function(){
            $('#content2').load('page2.html');
        });
    });
});

page1.html

page1.html

<div id="content2"></div>

它只适用于1次点击,第二次点击它加载page2.html为0,5

It's works fine for only 1 click, at the second click it loads page2.html for 0,5 seconds and then loads page1.html.

有什么问题?

谢谢

推荐答案

您的答案适用于我的Chrome,但尝试您没有双重 #content 元素

your answer works on my chrome, but try to empty the content to be sure that you are not having double #content elements

$(document).ready(function() {
    $('a.link').live('click', function() {
        $('#content:first').empty().load('page1.html', function(){
            $('#content2').load('page2.html');
        });
    });
});

这篇关于jquery函数将html代码加载到一个div,然后加载其他内容到div里面加载html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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