我目前正在为我在学校的课程之一创建网站。获取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一起使用。提前致谢。
谢谢,我忘了,我'.section'默认隐藏。感谢您指出了这一点。 – Shawn31313 2011-12-19 01:23:55