我创建了一个带有变量库的 php 模板,并没有将所有内容都拉入索引页面 我创建了一个基本脚本,在加载时使页面淡入淡出,并使它可以正常工作我想做的下一件事是使用我的导航栏链接将格式化内容拉入页面(因为我使用的是 foundation 4 框架)现在我尝试的代码如下
$(document).ready(function() {
var hash = window.location.hash.substr(1);
var href = $('#nav li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #content';
$('#content').load(toLoad)
}
});
$('#nav li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').hide('fast',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').show('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
});
想法是,onclick 会删除带有包装器的内容,显示加载 gif,然后加载存储在
中引用的链接中的页面内容但它不起作用只是重新加载整个页面。 . . .我试过阅读它说你可以使用
You can extract from another page using the load method thus >$('#targetElement').load('page.htm #container') syntax.
并使用 get 函数,但我并不擅长这个 jquery 是否有一种方法可以在 php 中完成,或者我所做的哪里出错了。
最佳答案
试试这个......你正在调用负载,并且内部函数不正确......
$('#nav li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').hide('fast',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
//window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,showNewContent);
}
function showNewContent() {
$('#content').show('normal',hideLoader);
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
关于php - jquery 更改文件中 "pages"的 php 模板中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17136834/