页面 加载时候 弹出 loading.gif 代码

来源:互联网 发布:mac装office破解版 编辑:程序博客网 时间:2024/05/04 20:38

<img id="submitImg" border="0" src="/test/images/loading.gif"
  style="position: absolute; display: none; visibility: visible">
 <input id="checkSubmitFlg" name="checkSubmitFlg" value="0"
  style="display: none">
 <script type="text/javascript"><!--
function submitTest() {   
var checkSubmitFlg = window.document.getElementById("checkSubmitFlg").value;   
if (checkSubmitFlg == '1') {
                alert("/u540e/u53f0/u6570/u636e/u5904/u7406/u4e2d/uff0c/u8bf7/u60a8/u7a0d/u7b49/u2026/u2026/u2026/u2026");
                return false;
        }
        window.document.getElementById("checkSubmitFlg").value="1";
var style="position: absolute;left:"+(window.screen.width/2-150)+"; top:"+(document.body.scrollTop+(document.body.clientHeight-150)/2)+";visibility:visible"
window.document.getElementById("submitImg").style.left=window.screen.width/2-150;
window.document.getElementById("submitImg").style.top=document.body.scrollTop+(document.body.clientHeight-150)/2;
window.document.getElementById("submitImg").style.display="";
window.status="/u4e1a/u52a1/u5904/u7406/u4e2d/u2026/u2026/u2026/u2026";
        return true;
}

//-->
</script>
<h:form onsubmit="return submitTest();">

 

 

以上是对画面改动代码 实现

自己写一个js,直接调用就可以实现

但是有个bug就是 在页面中有的按钮不实现loading图片加载,取消不了问题

一下是js代码

load();// onsubmit="return submitTest();"
function load() {
 document.forms[0].attachEvent('onsubmit', submitTest);
 document.forms[0].innerHTML = document.forms[0].innerHTML
   + "<img id='submitImg' border='0' src='/test/images/loading.gif'"
   + "style='position: absolute; display: none; visibility: visible'>"
   + "<input id='checkSubmitFlg' name='checkSubmitFlg' value='0'"
   + "style='display: none'> ";
}

function submitTest() {
 var checkSubmitFlg = window.document.getElementById("checkSubmitFlg").value;
 if (checkSubmitFlg == '1') {
  alert("/u540e/u53f0/u6570/u636e/u5904/u7406/u4e2d/uff0c/u8bf7/u60a8/u7a0d/u7b49/u2026/u2026/u2026/u2026");
  return false;
 }
 window.document.getElementById("checkSubmitFlg").value = "1";
 var style = "position: absolute;left:"
   + (window.screen.width / 2 - 150)
   + "; top:"
   + (document.body.scrollTop + (document.body.clientHeight - 150) / 2)
   + ";visibility:visible"
 window.document.getElementById("submitImg").style.left = window.screen.width / 2 - 150;
 window.document.getElementById("submitImg").style.top = document.body.scrollTop
   + (document.body.clientHeight - 150) / 2;
 window.document.getElementById("submitImg").style.display = "";
 window.status = "/u4e1a/u52a1/u5904/u7406/u4e2d/u2026/u2026/u2026/u2026";
 return true;
}