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');
});
});
});