<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ### 一,window對象概述 ![](https://box.kancloud.cn/2016-04-28_57215591871fe.jpg) BOM的核心對象是Window對象,它表示瀏覽器的一個實例。window對象處于JavaScript結構的最頂層,對于每個打開的窗口,系統都會自動為其創建window對象。所有瀏覽器都支持window對象,它表示瀏覽器窗口。所有JavaScript全局對象、函數以及變量均自動成為window對象的成員。全局變量是?window對象的屬性。全局函數是window對象的方法。甚至HTML DOM的document也是window對象的屬性之一。通過下面的兩句代碼我們可以看出window對象是BOM的頂層(核心)對象,所有對象都是通過它延伸出來的。因此調用它的子對象時可以不顯示的指明window對象: ~~~ window.document.getElementById("test"); ~~~ 與上述等價的寫法是: ~~~ document.getElementById("test"); ~~~ ### 二,window對象 (1)window對象的屬性和方法 window對象的屬性 ![](https://box.kancloud.cn/2016-04-28_572155919ace9.jpg) ![](https://box.kancloud.cn/2016-04-28_57215591b34e0.jpg) window對象的方法 ![](https://box.kancloud.cn/2016-04-28_57215591c7542.jpg) (2)系統對話框 Window對象可以在JavaScript中創建三種消息框:警告框、確認框、提示框。瀏覽器通過alert()方法,confirm()方法和prompt()方可以調用系網頁統對話框向用戶顯示信息。系統對話框與瀏覽器顯示的網頁沒有關系,也不包含HTML。 1,警告框:警告框經常用于確保用戶可以得到某些信息。當警告框出現后,用戶需要點擊確定按鈕才能繼續進行操作。 語法:alert("文本"); 2,提示框:提示框經常用于提示用戶在進入頁面前輸入某個值。當提示框出現后,用戶需要輸入某個值,然后點擊確認或取消按鈕才能繼續操縱。如果用戶點擊確認,那么返回值為輸入的值。如果用戶點擊取消,那么返回值為null。 語法:prompt("文本"); 3,確認框:確認框用于使用戶可以驗證或者接受某些信息。當確認框出現后,用戶需要點擊確定或者取消按鈕才能繼續進行操作。如果用戶點擊確認,那么返回值為 true。如果用戶點擊取消,那么返回值為?false。 語法:confirm("文本"); 綜合實例: ~~~ var name=prompt("請輸入您的名字",""); if (confirm(name!=null&&name!="")) { alert("你好!"+name); } else { alert("您沒有輸入名字!"); } ~~~ 3,新建窗口 使用window.open()方法可以導航到一個特定的URL,也可以打開一個新的瀏覽器窗口。它可以接受四個參數: window.open(url,name,feature,replace); 參數解釋: url:要加載的URL,設置打開窗口中顯示的文檔的URL,如果缺省或者為"",那么新窗口就不顯示任何文檔。 name:窗口的名稱或窗口目標。為新窗口命名。該名稱可以作為標簽和的target屬性值。如果名稱為已經存在的窗口的名稱,那么open方法就不再創建新的窗口,而只返回對指定窗口的引用,這種情況,第三個參數將被忽略。 feature:一個特性字符串,設置新窗口的顯示特性,可選參數。 replace:一個表示新頁面是否取代瀏覽器記錄中當前加載頁面的布爾值。設置是否在窗口的瀏覽歷史中給加載到新頁面的URL創建一個新條目,還是用它替換瀏覽歷史中的當前條目。 第三個特性字符串的參數: ![](https://box.kancloud.cn/2016-04-28_57215591e90fd.jpg) ![](https://box.kancloud.cn/2016-04-28_572155920aee9.jpg) 實例: ~~~ open("http://www.baidu.com","百度","width=400,height=400,top=200,left=200,toolbar=yes","_parent"); ~~~ 4,窗口頁面尺寸 有三種方法能夠確定瀏覽器窗口的尺寸(瀏覽器的視口,不包括工具欄和滾動條)。 a對于Internet Explorer、Chrome、Firefox、Opera 以及 Safari: ~~~ window.innerHeight;//瀏覽器窗口的內部高度 window.innerWidth;//瀏覽器窗口的內部寬度 ~~~ b對于 Internet Explorer 8、7、6、5: ~~~ document.documentElement.clientHeight; document.documentElement.clientWidth; ~~~ 或者 ~~~ document.body.clientHeight; document.body.clientWidth; ~~~ 實用的JavaScript方案(涵蓋所有瀏覽器)有兩個: 方案一: ~~~ var pageWidth=window.innerWidth; var pageHeight=window.innerHeight; if(typeof pageWidth!="number") { if(document.compatMode=="CSS1Compat")//標準模式 { pageWidth=document.documentElement.clientWidth; pageHeight=document.documentElement.clientHeigth; } else { pageWidth=document.body.clientWidth; pageHeight=document.body.clientHeigth; } } document.write("瀏覽器的內部窗口寬度:" + p ageWidth + ",高度:" + pageHeight + "。"); ~~~ 方案二: ~~~ var pageWidth=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth; var pageHeight=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight; document.write("瀏覽器的內部窗口寬度:" + pageWidth + ",高度:" + pageHeight + "。"); ~~~ 上述兩個方案運行的結果為: 瀏覽器的內部窗口寬度:1366,高度:607。 ### 三,screen對象 screen對象包含有關用戶屏幕的信息。Screen對象最常用的兩個屬性是:availWidth(可用的屏幕寬度)和availHeight(可用的屏幕高度)。 screen對象屬性: ![](https://box.kancloud.cn/2016-04-28_5721559223498.jpg) 實例: ~~~ document.write("可用寬度:" + screen.availWidth+","); document.write("可用高度:" + screen.availHeight); ~~~ 輸出:可用寬度:1366,可用高度:728 ### 四,history對象 history對象是保存上網的記錄,從窗口被打開的那一刻算起,包含瀏覽器的歷史。為了保護用戶隱私,對 JavaScript訪問該對象的方法做出了限制。 history對象的屬性和方法: ![](https://box.kancloud.cn/2016-04-28_5721559236a0c.jpg) 實例: ~~~ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>BOM</title> <script type="text/javascript"> function goBack() { if(history.length!=0) { history.back();//加載歷史列表中的前一個 URL } } document.write("這個網頁有"+history.length+"條歷史記錄!"); </script> </head> <body> <input type="button" value="轉到上一頁" onclick="goBack()" /> </body> </html> ~~~ 運行的結果為: ![](https://box.kancloud.cn/2016-04-28_572155924cab8.jpg) ### 五,location對象 location對象是BOM對象之一,它提供了與當前窗口中加載的文檔有關的信息,還提供了一些導航功能。location對象用于獲得當前頁面的地址(URL),并把瀏覽器重定向到新的頁面。? location對象的屬性: ![](https://box.kancloud.cn/2016-04-28_572155925d24c.jpg) ![](https://box.kancloud.cn/2016-04-28_572155926ee3a.jpg) location對象的方法: ![](https://box.kancloud.cn/2016-04-28_572155927d127.jpg) 實例:獲取諸如?name=liu&psw=123這種類型的鍵值對。 ~~~ function getArgs() { //創建一個存放鍵值對的數組 var args=[]; //去除?號 var qs=location.search.length>0?location.search.substring (1):""; //按&字符串拆分數組 var items=qs.split("&"); var item =null,name=null,value=null; //遍歷 for(var i=0;i<items;i++) { item=items[i].split("="); name=item[0]; value=item[1]; //把鍵值對存放到數組中去 args[name]=value; } return args; } var args=getArgs(); //調用函數 alert(args["name"]); alert(args["psw"]); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看