iframe加載loading...

    <body>   
     <div      id="load" align="center">
<img src="http://sc.cnwebshow.com/upimg/allimg/070707/01294420.gif" />&nbsp;loading...
     </div>                                                      <!-- 首先放一個div,用做loading效果 -->
     <iframe     id="demo"      src="http://www.baidu.com/"     width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0"></iframe>        <!-- src 裏面放你想要的網頁-->
         <script      type="text/javascript">   
         //<![CDATA[   
     var      a      =      document.getElementById("demo");   
     var      b      =      document.getElementById("load");   
     a.style.display      =      "none";                     //隱藏
     b.style.display      =      "block";                     //顯示
     a.onreadystatechange      =      function()      {   
     if      (this.readyState=="complete")      {       //最近才知道的。不然也寫不出來。
                                                                 // 解釋:一個iframe加載完畢的狀態是complete,
                                                                 // 就象xmlhttp裏的那個==4一樣,這些都是規定的...
     b.innerHTML      =      "load      complete!";    
     b.style.display      =      "none";  
     a.style.display      =      "block";   
     }   
     }   
         //]]>   

         </script>   
     </body>

 

看了人家的代碼:
              var state = this.readyState;
            
if (state == "loaded" || state == "interactive" || state == "complete") {
              
this.onreadystatechange = null;
            b.innerHTML      =      "load      complete!";    
             b.style.display      =      "none";  
            a.style.display      =      "block";   
             }
               else
              {
               window.setTimeout(  "回調函數"    , 100);
             }
好象比我的要更加嚴密。
但我有點不懂。我的函數是這麼寫的     a.onreadystatechange      =      function()      {}
那麼我這個回調函數該怎麼寫。
看人家的代碼:
function on(){
if ( window.onload )
{
alert( "page onload." );
}
else{
window.setTimeout( on, 1000);
}
}
on();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章