-1
我遇到了加載代碼的問題。客戶想要點擊一個標籤時會顯示一個隱藏的加載器div,而當(通過點擊)其他頁面完全加載時,加載器將被隱藏。頁面加載器問題
這裏是示例代碼
function pageLoaded(){
var hideit = document.getElementById("loadUnload");
hideit.style.display= "none";
}
window.onload = pageLoaded;
function pageUnloaded(){
var showit = document.getElementById("loadUnload");
showit.style.display= "block";
}
window.addEventListener("load", pageLoaded, false);
window.addEventListener("unload", pageUnloaded, false);
window.addEventListener("unbeforeunload", pageUnloaded, false);
window.onload = pageLoaded;
function changeClass(elem, classDark,classSelected) {
for(objIndex = 0; objIndex < elem.parentNode.children.length; objIndex++) {
var obj = elem.parentNode.children[objIndex];
if(obj.className == classSelected) obj.className = classDark;
}
elem.className = (elem.className == classDark)?classSelected:classDark;
elem.children[0].children[0].checked = (elem.className == classSelected) ? true : false;
}
function spinner(){
var lists = document.getElementsByTagName("a");
var spinnerdiv = document.getElementById("loadUnload");
for (var i = 0; i < lists.length; i++)
{
lists[i].onclick = function(){
spinnerdiv.style.display= "block";
}
}
}
and the html code is like that
<**div id="loadUnload">
<**div id="loadingDiv" class="centered"><div class="text">loading...</div></div>
<**/div>
你的問題是什麼? – 2011-04-07 11:40:32
你應該真的**使用'var'作爲你的循環變量。否則,它們是全局的,並且只要具有相同循環變量名的循環(例如'i')嵌套(即使在不同的函數中),它們也可能會中斷! – ThiefMaster 2011-04-07 11:50:59
我的問題是=我怎麼做到這一點 - 當點擊一個標記隱藏的加載器div將被顯示,當(通過點擊)其他頁面完全加載的加載器將被隱藏。 – tsdln 2011-04-07 11:58:01