如何关闭AJAX加载的页面,并带回旧内容?加载、页面、内容、AJAX

2023-09-10 21:09:45 作者:与你深欢

我正在开发一个网页组合的网站,这将拉动项目从单独的HTML文件。所以,现在我有这个code加载新的URL(特别是 #project DIV)到当前分区#端口含量

I'm developing a one page portfolio site which will pull projects from separate html files. So, currently I have this code that loads the new URL (specifically the #project div) into the current div #port-content.

我custom.js部分如下:

var hash = window.location.hash.substr(1);
var href = $('.ajax').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
    var toLoad = hash+'.html #project';
    $('#port-content').load(toLoad)
        }                                           
    });

    $('a.port-more').click(function(){                        
        var toLoad = $(this).attr('href')+' #project';
        $('#port-content').hide('normal',loadContent);
        window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
        function loadContent() {
            $('#port-content').load(toLoad,'',showNewContent())
        }
        function showNewContent() {
            $('#port-content').show('normal');
        }
        return false;
    });

我如何关闭这个内容,并带回我原来的#端口含量 DIV。我试图创建一个新的功能,做相反的,但没有奏效。

How can I close this content and bring back my original #port-content div. I tried to create a new function doing the opposite but it didn't work.

任何想法?

推荐答案

使用的.data()听起来像是正确的选项这一点。

Using .data() sound like the correct option for this.

function loadContent() {
   if(!$('#port-content').data('default')) $("#port-content").data('default', $("#port-content").html());
   $('#port-content').load(toLoad,'',showNewContent())
}
// and create another function to load the default
function loadDefault() {
  $('#port-content').html($("port-content").data('default'));
}
 
精彩推荐
图片推荐