页面加载器问题

时间:2011-04-07 11:39:07

标签: javascript loading

我遇到加载代码的问题。客户希望在点击标签时显示隐藏的加载器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>

1 个答案:

答案 0 :(得分:0)

我建议你使用AJAX和Jquery。我相信这将是最好的方法,一旦你习惯了它就会解决你的问题。