http://zentili.koding.com我已經得到這個JavaScript,加載索引頁的主#content div內的鏈接菜單項的內容,並應用散列加載頁面的名稱減去'.php',否則加載散列+'.php',如果它輸入在URL中。作品非常好。另一方面,ENG/ITA條目在散列之前的url內部添加?locale = lang_LANG,以便本地化也可以正常工作。如果你看起來不錯,你可能會注意到當你在ENG和ITA之間切換時,索引內容會在去散列之前出現一會兒。我知道這是因爲頁面首先被加載,然後被帶到哈希,但我想知道是否有某種方法隱藏主頁,並在加載時直接進入哈希位置。加載頁面在其散列,然後直接顯示結果,而不顯示索引第一
這裏我的菜單代碼:
<script type="text/javascript">
$(document).ready(function() {
var hash = window.location.hash.substr(1);
var href = $('#menubar a.item').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-4)){
var toLoad = hash+'.php';
$('#content').load(toLoad);
$("#menubar a.item").removeClass("current");
$(this).addClass("current");
}
});
$('#menubar a.item').click(function(){
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
var toLoad = $(this).attr('href');
$('#content').fadeOut('fast',loadContent);
function loadContent() {
$('#content').load(toLoad,'',showNewContent) }
function showNewContent() {
$('#content').fadeIn('fast'); }
$("#menubar a.item").removeClass("current");
$(this).addClass("current");
return false;
});
});
function goENG(){
var hash = window.location.hash;
var eng = '?locale=en_EN';
window.location.replace(eng+hash) ;
};
function goITA(){
var hash = window.location.hash;
var ita = '?locale=it_IT';
window.location.replace(ita+hash) ;
};
</script>
功能goENG()和goITA()通過在ENG和ITA一的onclick調用。我希望找到一些解決方案。
對此有幫助嗎? –
我如何在後臺「加載」散列?如果(window.location.hash){('#content')。attr('visibility','visible'); }; } })添加'$(document).ready(function() ;'with'visibility:hidden;'on #content根本不顯示內容! – zentili
我已經更新了上面的答案。你需要做的可見性:隱藏在CSS中做可見性在js中可見後,檢查散列並加載DOM –