J2EE社區(qū)

          茍有恒,何必三更起五更眠;
          最無益,只怕一日曝十日寒.
          posts - 241, comments - 318, trackbacks - 0, articles - 16

          一些頁面自動跳轉(zhuǎn)的實(shí)現(xiàn)

          Posted on 2009-03-05 15:16 xcp 閱讀(8634) 評論(5)  編輯  收藏 所屬分類: Javascript
          功能:5秒后,自動跳轉(zhuǎn)到同目錄下的02view.html文件
           
          1)html的實(shí)現(xiàn)
          <head>
          <meta http-equiv="refresh" content="5;url=02view.html">
          </head>

          優(yōu)點(diǎn):簡單
          缺點(diǎn):Struts Tiles中無法使用
           
          2)javascript的實(shí)現(xiàn)
          <script language="javascript" type="text/javascript">
             setTimeout(
          "javascript:location.href='02view.html'"5000); 
          </script>

          優(yōu)點(diǎn):靈活,可以結(jié)合更多的其他功能
          缺點(diǎn):受到不同瀏覽器的影響
           
          3)結(jié)合了倒數(shù)的javascript實(shí)現(xiàn)(IE)
          <span id="totalSecond">5</span>

          <script language="javascript" type="text/javascript">
          var second = totalSecond.innerText;
          setInterval(
          "redirect()"1000);
          function redirect(){ 
          totalSecond.innerText
          =--second; 
          if(second<0) location.href='02view.html';
          }
          </script>

          優(yōu)點(diǎn):更人性化
          缺點(diǎn):firefox不支持(firefox不支持span、div等的innerText屬性)
           
          3')結(jié)合了倒數(shù)的javascript實(shí)現(xiàn)(firefox)
          <script language="javascript" type="text/javascript">
              
          var second = document.getElementById('totalSecond').textContent;
              setInterval(
          "redirect()"1000);
              
          function redirect()
              {
                  document.getElementById('totalSecond').textContent 
          = --second;
                  
          if (second < 0) location.href = '02view.html';
              }
          </script>

          4)解決Firefox不支持innerText的問題
          <span id="totalSecond">5</span>

          <script language="javascript" type="text/javascript">
          if(navigator.appName.indexOf("Explorer"> -1){
              document.getElementById('totalSecond').innerText 
          = "my text innerText";
          else{
              document.getElementById('totalSecond').textContent 
          = "my text textContent";
          }
          </script>

          5)整合3)和3')
          <span id="totalSecond">5</span>

          <script language="javascript" type="text/javascript">
              
          var second = document.getElementById('totalSecond').textContent;

              
          if (navigator.appName.indexOf("Explorer"> -1)
              {
                  second 
          = document.getElementById('totalSecond').innerText;
              } 
          else
              {
                  second 
          = document.getElementById('totalSecond').textContent;
              }


              setInterval(
          "redirect()"1000);
              
          function redirect()
              {
                  
          if (second < 0)
                  {
                      location.href 
          = '02view.html';
                  } 
          else
                  {
                      
          if (navigator.appName.indexOf("Explorer"> -1)
                      {
                          document.getElementById('totalSecond').innerText 
          = second--;
                      } 
          else
                      {
                          document.getElementById('totalSecond').textContent 
          = second--;
                      }
                  }
              }
          </script>



          名稱: ?4C.ESL | .↗Evon
          口號: 遇到新問題?先要尋找一個方案乄而不是創(chuàng)造一個方案こ
          mail: 聯(lián)系我


          Feedback

          # re: 一些頁面自動跳轉(zhuǎn)的實(shí)現(xiàn)   回復(fù)  更多評論   

          2009-03-05 18:45 by 44you
          不錯

          # re: 一些頁面自動跳轉(zhuǎn)的實(shí)現(xiàn)   回復(fù)  更多評論   

          2009-03-06 07:47 by Rui
          學(xué)習(xí)了:)

          # re: 一些頁面自動跳轉(zhuǎn)的實(shí)現(xiàn)   回復(fù)  更多評論   

          2009-03-06 09:28 by 曉江小子
          我可以轉(zhuǎn)載么。。。。

          # re: 一些頁面自動跳轉(zhuǎn)的實(shí)現(xiàn)   回復(fù)  更多評論   

          2009-05-17 02:36 by xiter
          不錯 支持

          # re: 一些頁面自動跳轉(zhuǎn)的實(shí)現(xiàn)   回復(fù)  更多評論   

          2009-11-27 18:20 by 第三方
          范甘迪
          主站蜘蛛池模板: 鄂托克前旗| 南平市| 龙岩市| 腾冲县| 怀仁县| 靖边县| 平邑县| 伊吾县| 夏河县| 正蓝旗| 东乌珠穆沁旗| 肃南| 四平市| 耒阳市| 都安| 哈尔滨市| 南雄市| 南部县| 淅川县| 常德市| 龙南县| 昌图县| 滨海县| 厦门市| 冀州市| 大同县| 铜梁县| 扶绥县| 阳山县| 新沂市| 浪卡子县| 湾仔区| 阿图什市| 中牟县| 镇宁| 淮安市| 德阳市| 扶风县| 家居| 彰武县| 平阴县|