【发布时间】:2013-07-12 16:23:27
【问题描述】:
我想使用散列进行导航,但我的脚本会在每次页面加载时将初始散列重置为#home,无论我在 url 中添加什么散列:
这是测试散列是否存在以及在#content 中加载什么的脚本:
$page = $('#content');
if(window.location.hash == 'home') {
$xmlFile = 'xml/home.xml';
$("#content").createHomeEntry();
} else if(window.location.hash == 'news') {
$xmlFile = 'xml/news.xml';
$("#content").createNewsEntry();
} else if (window.location.hash == 'biography'){
$xmlFile = 'xml/bio.xml';
$("#content").createBioEntry();
} else if (window.location.hash == 'awards'){
$xmlFile = 'xml/awards.xml';
$("#content").createBioEntry();
} else if (window.location.hash == 'discography'){
$xmlFile = 'xml/discography.xml';
$("#content").createBioEntry();
}else{
alert('this should fire off because there is no hash but it doesnt');
$xmlFile = 'xml/home.xml';
$("#content").createHomeEntry();
}
somoeone 可以在这里帮助我,或者告诉我为什么这个脚本将 #home 设置为默认值。
【问题讨论】:
标签: javascript jquery ajax hash navigation