jQuery的AJAX页面加载,DIV具体 [英] jQuery AJAX page loading, DIV specific
问题描述
试图把从一个调用的jQuery的.load功能页面的特定DIV。
Trying to bring in a specific DIV from a page called by the jQuery .load function.
这是在code,我有:
This is the code i have:
<script type="text/javascript">
$('ul.navigation li a').click(function() {
$('#content-wrap').fadeOut(500);
var targetPage = $(this).attr('href')
setTimeout(function() {
$('#content-wrap').load(targetPage, function() {
$('#content-wrap').fadeIn(500);
});
});
return false;
});
</script>
...和它的作品 - 但它调用整页,而不是特定的区域...
...and it works - but it calls the whole page, rather than a specific area...
干杯!
推荐答案
您正在试图加载一个页面的片段的,而不是整个页面。如果你深入挖掘的文档,你会看到你需要改变你的 targetPage
变量只是略有下降。
You're trying to load a page fragment rather than the whole page. If you dig deeper into the documentation, you'll see you need to change your targetPage
variable just slightly.
var targetPage = $(this).attr('href');
targetPage += " #content-wrap";
这将在 targetPage
变量更改为沿 HTTP的东西线://site.url#内容包装
键,将获取的#内容包装
元素,而不是整个页面的内容。
This will change the targetPage
variable to something along the lines of http://site.url #content-wrap
and will fetch the contents of the #content-wrap
element rather than the whole page.
- 查看加载页面片段的
.load()第
更多。李文档>
- See the Loading Page Fragments section of the
.load()
documentation for more.
这篇关于jQuery的AJAX页面加载,DIV具体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!