我正在开发一个页面组合网站,它将从单独的html文件中提取项目。所以,目前我有这个代码加载新的URL(特别是#project
div)到当前div #port-content
。如何关闭ajax加载的页面并返回旧内容?
我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;
});
如何关闭这个内容并带回我原来#port-content
股利。我试图创建一个相反的新功能,但它不起作用。
任何想法?
嗨Starx,谢谢你的回答,但是这打破了功能。如何包括一个$('a.close-port')?click(function(){\t ?? – jwaldeck 2012-04-27 21:59:38
@ user1361999,把这两个函数放在click处理程序之外,如果你想要我可以创建一个小提琴检查它 – Starx 2012-04-27 22:02:11
不知道如何做到这一点与AJAX函数..此外,这个函数本身已经很多错误d.pr/i/x7bJ。可能必须聘请一个jQuery专家来看看这个..反正。 – jwaldeck 2012-04-27 22:27:00