2011-12-19 52 views
1

我目前正在为我在学校的课程之一创建网站。获取URL的查询部分并对其执行操作

我想要设置网站,所以它看起来不像它的重装。

通过执行查询中的页面:?page=index。 我通过在Div中淡入取决于查询来做到这一点。我知道页面实际上是重新加载的,但它看起来不像是不会重新加载淡入淡出。你可以看到我的网站在这里:http://yolatools.yolasite.com/resources/project.html?page=index

现在唯一的问题是,当我做?page=fcduj它假设显示页面未找到DIV。

我的代码是:

function load(){ 
    var profile=location.search; 
    if(profile=="?page=index") 
    { 
    $('.section, #home').fadeIn(1500); 
    $('.i').addClass('active'); 
    $('.a, .m').addClass('grey'); 
    } 
    else if(profile=="?page=about") 
    { 
    $('.section, #about').fadeIn(1500); 
    $('.a').addClass('active'); 
    $('.m, .i').addClass('grey'); 
    } 
    else if(profile=="?page=more"){ 
    $('.section, #more').fadeIn(1500); 
    $('.m').addClass('active'); 
    $('.a, .i').addClass('grey'); 
    } 
    else if(profile==="") 
    { 
    location.href = '?page=index'; 
    } 
    if(profile !== '?page=index' && profile !== '?page=about' && profile !== '?page=more') { 
    var rsts = profile.substr(6); 
    $('#query').html(rsts); 
    $('#wrong').fadeIn(1500); 
    } 
} 

我在body标签启动此功能与onload

是想使未发现DIV显示页面的部分是:

if(profile !== '?page=index' && profile !== '?page=about' && profile !== '?page=more') { 
    var rsts = profile.substr(6); 
    $('#query').html(rsts); 
    $('#wrong').fadeIn(1500); 
} 

但它似乎并没有工作,但我不知道为什么。对于?page=index我不想使用PHP,即使这通常与PHP一起使用。提前致谢。

回答

1

#wrong DIV显示,但父.section股利不显示。

变化,如果语句:

if(profile !== '?page=index' && profile !== '?page=about' && profile !== '?page=more') { 
    var rsts = profile.substr(6); 
    $('#query').html(rsts); 
    $('.section, #wrong').fadeIn(1500); 
} 
+0

谢谢,我忘了,我'.section'默认隐藏。感谢您指出了这一点。 – Shawn31313 2011-12-19 01:23:55

0

创建自定义404错误页面,已需要的JS

0

本替换你的JavaScript:

function home(){ 

$('#home').fadeIn(1000); 

$('#about, #more').fadeOut(10); 

} 

function about(){ 

$('#about').fadeIn(1000); 

$('#home, #more').fadeOut(100); 

} 

function more(){ 

$('#more').fadeIn(1000); 

$('#about, #home').fadeOut(100); 

} 

function menu(){$('#h1').fadeIn(1000);setTimeout('other()',1000)} 

function other(){ 

$('#h3').fadeIn(500); 

setTimeout('$("#menu").fadeIn(500);', 500) 

} 

function load(){ 

var profile=location.search; 
if(profile=="?page=index") 

{ 

$('.section, #home').fadeIn(1500);setTimeout('menu()', 1500) 

} 

else if(profile=="?page=about") 

{ 

$('.section, #about').fadeIn(1500);setTimeout('menu()', 1500) 

} 

else if(profile=="?page=more"){ 

$('.section, #more').fadeIn(1500);setTimeout('menu()', 1500) 

} 

else if(profile==="") 

{ 

location.href = '?page=index'; 

} 



else { 

var rsts = profile.substr(6); 

$('#query').html(rsts); 

$('#wrong,#articles').fadeIn(1500); 

$('#about, #more, #home').hide(); 

} 



} 
相关问题