jquery使用“更改php模板中的内容”;“第页”;在里面 我创建了一个带有变量库的PHP模板,并不是所有的都被拉到索引页中,我已经创建了一个基本的脚本,这个页面在加载和卸载的过程中消失了,并且已经得到了工作,接下来我要做的就是用我的Navar链接把格式化的内容拉进页面(就像我正在使用的基础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; }); }); $(文档).ready(函数(){ var hash=window.location.hash.substr(1); var href=$('#nav li a')。每个(函数(){ var href=$(this.attr('href'); if(hash==href.substr(0,href.length-5)){ var toLoad=hash+'.html#content'; $(“#内容”).load(toLoad) } }); $('#nav li a')。单击(函数(){ var toLoad=$(this.attr('href')+'#content'; $('content').hide('fast',loadContent); $(“#加载”).remove(); $(“#包装器”).append('LOADING…'); $('加载').fadeIn('正常'); window.location.hash=$(this.attr('href').substr(0,$(this.attr('href').length-5); 函数loadContent(){ $('#content').load(toLoad',showNewContent()) } 函数showNewContent(){ $('#content').show('normal',hideLoader()); } 函数hideLoader(){ $('加载').fadeOut('正常'); } 返回false; }); });

jquery使用“更改php模板中的内容”;“第页”;在里面 我创建了一个带有变量库的PHP模板,并不是所有的都被拉到索引页中,我已经创建了一个基本的脚本,这个页面在加载和卸载的过程中消失了,并且已经得到了工作,接下来我要做的就是用我的Navar链接把格式化的内容拉进页面(就像我正在使用的基础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; }); }); $(文档).ready(函数(){ var hash=window.location.hash.substr(1); var href=$('#nav li a')。每个(函数(){ var href=$(this.attr('href'); if(hash==href.substr(0,href.length-5)){ var toLoad=hash+'.html#content'; $(“#内容”).load(toLoad) } }); $('#nav li a')。单击(函数(){ var toLoad=$(this.attr('href')+'#content'; $('content').hide('fast',loadContent); $(“#加载”).remove(); $(“#包装器”).append('LOADING…'); $('加载').fadeIn('正常'); window.location.hash=$(this.attr('href').substr(0,$(this.attr('href').length-5); 函数loadContent(){ $('#content').load(toLoad',showNewContent()) } 函数showNewContent(){ $('#content').show('normal',hideLoader()); } 函数hideLoader(){ $('加载').fadeOut('正常'); } 返回false; }); });,php,jquery,html,onclick,zurb-foundation,Php,Jquery,Html,Onclick,Zurb Foundation,其思想是,onclick它使用包装器删除内容并显示加载gif,然后加载页面内容,该页面内容存储在 但它不工作只是重新加载整个页面。我试过阅读,上面说你可以使用 您可以使用load方法从另一个页面提取,因此>$(“#targetElement”).load('page.htm#container')语法 使用get函数,但我并不擅长这个jquery,有没有一种方法可以在php中实现它,或者我所做的工作哪里出了问题。试试这个……你调用的是load,里面的函数不正确 $('#nav li a').cl

其思想是,onclick它使用包装器删除内容并显示加载gif,然后加载页面内容,该页面内容存储在

但它不工作只是重新加载整个页面。我试过阅读,上面说你可以使用

您可以使用load方法从另一个页面提取,因此>$(“#targetElement”).load('page.htm#container')语法


使用get函数,但我并不擅长这个jquery,有没有一种方法可以在php中实现它,或者我所做的工作哪里出了问题。

试试这个……你调用的是load,里面的函数不正确

$('#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;

});
$('nav li a')。单击(函数(){
var toLoad=$(this.attr('href')+'#content';
$('content').hide('fast',loadContent);
$(“#加载”).remove();
$(“#包装器”).append('LOADING…');
$('加载').fadeIn('正常');
//window.location.hash=$(this.attr('href').substr(0,$(this.attr('href').length-5);
函数loadContent(){
$(“#content”).load(toLoad,showNewContent);
}
函数showNewContent(){
$('content').show('normal',hideLoader);
}
函数hideLoader(){
$('加载').fadeOut('正常');
}
返回false;
});

当用户单击链接时,默认情况下浏览器将卸载当前页面并加载该链接指示的页面

$('#your-context').click(function(event) {
    event.preventDefault();
    /**
     * the rest of your code here
     */
});
您需要防止浏览器的默认行为,为此,您需要在为该链接触发的单击事件上调用
.preventDefault()
方法

$('#your-context').click(function(event) {
    event.preventDefault();
    /**
     * the rest of your code here
     */
});

谢谢你的回复,但仍然无法重新加载整个页面。所以为了简化事情,我把加载条拿出来,对navbar和div元素使用id,现在还在工作,还是在重新加载整个页面?只是问一件很愚蠢的事。在我打开的页面上,它应该只有页面中的或整个页面的标记哦……是的……它应该只有内容,没有标题等等……就像它应该只有你想显示的内容一样,没有其他内容。atm在上面和下面得到以下建议//
JavaScript文档$(“#nav li a”)。单击(函数(事件){event.preventDefault()var toLoad=$(this).attr('href')+'#content';$('#content').hide('fast',loadContent);//window.location.hash=$(this).attr('href').substr(0,$(this.attr('href').length-5);函数loadContent(){$('content').load(toLoad,showNewContent);}函数showNewContent(){$('返回false;});
并获取所有标题,新页面上的所有内容都是,它所做的只是加载到新页面上,而不是格式化