页面加载器问题
我在加载代码时遇到问题。客户希望当单击标签时,将显示隐藏的加载器 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>
i got a problem with loading code. customer wants when clicked an tag a hidden loader div will be shown and when (by clicked) other page completely loaded the loader will be hidden.
here is the sample code
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您使用 AJAX 和 Jquery。我相信这将是最好的方法,一旦您习惯使用它,它就会解决您的问题。
I recommend you use AJAX and Jquery. I believe this will be the best approach, and it will solve your problem once you get used to working with it.