Ajax 小記with 用法

先看例子:

Js代碼  收藏代碼
  1. <script type="text/javascript">      
  2.          //可斷定這個瀏覽器是IE 或非IE, 注意if 的判斷條件, 如果這個瀏覽器對象的innerWidth返回值爲true, 證明      
  3.          //這個瀏覽器不是IE.      
  4.          if(window.innerWidth) {      
  5.                  document.write("no IE inner: "+window.innerWidth+"  x  "+window.innerHeight);                     
  6.          } else {      
  7.              document.write("IE:"+document.body.clientWidth+" x "+document.body.clientHeight);      
  8.          }      
  9.  </script>      

 

 如果用with 程序可簡化爲:

Js代碼  收藏代碼
  1. <script type="text/javascript">      
  2.     if(window.innerWidth) {      
  3.         with(window) {      
  4.             document.write("no IE inner: "+innerWidth+"  x  "+innerHeight);      
  5.         }                     
  6.     } else {      
  7.         with(document.body) {                      
  8.             document.write("IE:"+clientWidth+" x "+clientHeight);      
  9.         }      
  10.     }      
  11. </script>    

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章