久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      javascript中window的意思是什么

      在javascript中,window的意思為“窗口”,是一個內(nèi)置的宿主對象,表示瀏覽器窗口,所有瀏覽器都支持該對象。所有JavaScript全局對象、函數(shù)以及變量均會自動成為window對象的成員。

      javascript中window的意思是什么

      本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

      在javascript中,window的意思為“窗口”,是一個內(nèi)置的宿主對象。

      window對象是BOM中所有對象的核心,除了是BOM中所有對象的父對象外,還包含一些窗口控制函數(shù)。

      宿主對象就是執(zhí)行JS腳本的環(huán)境提供的對象,是瀏覽器提供的對象。所有的BOM和DOM都是宿主對象。

      Window 對象

      所有瀏覽器都支持 window 對象。它表示瀏覽器窗口。

      所有 JavaScript 全局對象、函數(shù)以及變量均自動成為 window 對象的成員。

      • 全局變量是 window 對象的屬性。

      • 全局函數(shù)是 window 對象的方法。

      甚至 HTML DOM 的 document 也是 window 對象的屬性之一:

      window.document.getElementById("header");

      與此相同:

      document.getElementById("header");

      1、全局的window對象

        JavaScript中的任何一個全局函數(shù)或變量都是window的屬性。

      <script type="text/javascript">     var name="撼地神牛";     document.write(window.name); </script>

      2、window與self對象

        self對象與window對象完全相同,self通常用于確認就是在當前的窗體內(nèi)。

      <script type="text/javascript">     document.write(window == self);      //必須相等,永遠都相等   document.write(window.Top == window.self);  //判斷當前框架是否是主框架 </script>

        window、self、window.self三者是等價的。

      3、window的子對象

        window的主對象主要有如下幾個:

      • JavaScript document 對象

      • JavaScript frames 對象

      • JavaScript history 對象

      • JavaScript location 對象

      • JavaScript navigator 對象

      • JavaScript screen 對象

      4、window函數(shù)索引(僅對IE有效)

        窗體控制函數(shù):

      • JavaScript moveBy() 函數(shù):從當前位置水平移動窗體x個像素,垂直移動窗體y個像素,x為負數(shù),將向左移動窗體,y為負數(shù),將向上移動窗體。

      • JavaScript moveTo() 函數(shù):移動窗體左上角到相對于屏幕左上角的(x,y)點,當使用負數(shù)做為參數(shù)時會把窗體移出屏幕的可視區(qū)域。

      • JavaScript resizeBy() 函數(shù):相對窗體當前的大小,寬度調(diào)整w個像素,高度調(diào)整h個像素。如果參數(shù)為負值,將縮小窗體,反之擴大窗體。

      • JavaScript resizeTo() 函數(shù):把窗體寬度調(diào)整為w個像素,高度調(diào)整為h個像素。

      <body>     <input type="button" id="btn1" value="先設(shè)置窗體固定大小!" onclick="window.resizeTo(500,500);" />     <input type="button" id="btn2" value="再縮小10像素!" onclick="window.resizeBy(-10,-10);" />     <input type="button" id="btn2" value="上!" onclick="window.moveBy(0,-5);" />     <input type="button" id="btn2" value="下!" onclick="window.moveBy(0, 5);" />     <input type="button" id="btn2" value="左!" onclick="window.moveBy(-5, 0);" />     <input type="button" id="btn2" value="右!" onclick="window.moveBy(5, 0);" />     <input type="button" id="btn2" value="距離左上角左邊100像素,頂部200像素" onclick="window.moveTo(100, 200);" /> </body>

        窗體滾動軸控制函數(shù):

      • JavaScript scrollTo() 函數(shù):在窗體中如果有滾動條,將橫向滾動條移動到相對于窗體寬度為x個像素的位置,將縱向滾動條移動到相對于窗體高度為y個像素的位置。

      • JavaScript scrollBy() 函數(shù):如果有滾動條,將橫向滾動條移動到相對于當前橫向滾動條的x個像素的位置(就是向左移動x像素),將縱向滾動條移動到相對于當前縱向滾動條高度為y個像素的位置(就是向下移動y像素)。

        注意區(qū)別,一個是相對當前窗口,一個是相當現(xiàn)在滾動條的位置。

      <div style="height:150%; width:150%; background-color:#ddd">     <input type="button" id="btn1" value="移動滾動條!" onclick="window.scrollTo(100,100);" />  //相當于設(shè)置絕對位置     <input type="button" id="btn1" value="移動滾動條!" onclick="window.scrollBy(100,100);" />  //相當于累加 </div>

        窗體焦點控制函數(shù):

      • JavaScript focus() 函數(shù):使窗體或空間獲得焦點

      • JavaScript blur() 函數(shù):使窗體或控件失去焦點

      <div>     <input type="button" value="獲得焦點" onclick="document.getElementById('testInput').focus()" />     <input type="button" value="失去焦點" onclick="document.getElementById('testInput').blur()" />     <input type="text" value="text" id="testInput" onblur="alert('我已失去焦點')" /> </div>

        新建窗體函數(shù):

      • JavaScript open() 函數(shù):打開(彈出)一個新的窗體
      • JavaScript close() 函數(shù):關(guān)閉窗體
      • JavaScript opener 屬性:通過opener可以實現(xiàn)跨窗體之間的通訊,但是要保證是在同一域名下,而且一個窗體要包含另一個窗體的opener。

        window.open(url, name, features, replace);

        open函數(shù)參數(shù)說明:

      • url — 要載入窗體的URL;
      • name — 新建窗體的名稱(也可以是HTML target屬性的取值,目標);
      • features — 代表窗體特性的字符串,字符串中每個特性使用逗號分隔;
      • replace — 一個布爾值,說明新載入的頁面是否替換當前載入的頁面,此參數(shù)通常不用指定。

        open方法示例:

        <a href="2.html" target="2">在新窗口打開連接</a>   <a href="#" onclick="window.open('http://www.google.com','2');">在已建立連接的頁面打開新地址</a>

        首先使用普通HTML鏈接打開一個頁面(target名為dreamdu),之后使用open函數(shù)打開另一個頁面,瀏覽器首先要查找是否有名稱為dreamdu的窗體,如果有,就在這個窗體中加載open的地址。

        經(jīng)過設(shè)置的open

      window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')

        彈窗方法:

      方法一:<body onload="openwin()"> 瀏覽器讀頁面時彈出窗口;   方法二:<body onunload="openwin()"> 瀏覽器離開頁面時彈出窗口;

        open函數(shù)第三個參數(shù)features說明:

      參數(shù)名稱 類型 說明
      height Number 設(shè)置窗體的高度,不能小于100
      left Number 說明創(chuàng)建窗體的左坐標,不能為負值
      location Boolean 窗體是否顯示地址欄,默認值為no
      resizable Boolean 窗體是否允許通過拖動邊線調(diào)整大小,默認值為no
      scrollable Boolean 窗體中內(nèi)部超出窗口可視范圍時是否允許拖動,默認值為no
      toolbar Boolean 窗體是否顯示工具欄,默認值為no
      top Number 說明創(chuàng)建窗體的上坐標,不能為負值
      status Boolean 窗體是否顯示狀態(tài)欄,默認值為no
      width Number 創(chuàng)建窗體的寬度,不能小于100

        特性字符串中的每個特性使用逗號分隔,每個特性之間不允許有空格。

        window.open函數(shù)新建立窗體后會返回新建窗體的window對象,通過此對象可以控制窗體(移動,改變大小,關(guān)閉)。

        close函數(shù):

      <input type="button" value="關(guān)閉已經(jīng)打開的窗體!" onclick="window.close();" />

        self.close();配合上setTimeout()可以實現(xiàn),打開的窗口定時關(guān)閉的效果。

        對話框函數(shù):

      • JavaScript alert() 函數(shù):彈出消息對話框(對話框中有一個OK按鈕)

      • JavaScript confirm() 函數(shù):彈出消息對話框(對話框中包含一個OK按鈕與Cancel按鈕)

      • JavaScript prompt() 函數(shù):彈出消息對話框(對話框中包含一個OK按鈕、Cancel按鈕與一個文本輸入框)

        alert();

        不說。

        confirm(str);

        confirm()消息對話框是排它的,也就是在用戶點擊對話框的按鈕前,不能進行任何其它操作。

      if(confirm("確定跳大?")) {     alert("果斷跳大"); }else{     alert("猥瑣打錢"); }

        顯示如下:

        javascript中window的意思是什么  

       prompt(str1, str2);

        函數(shù)有兩個參數(shù)

      • str1 — 要顯示在消息對話框中的文本,不可修改
      • str2 — 文本框中的內(nèi)容,可以修改
      var sResult=prompt("請在下面輸入你的姓名", "撼地神牛");if(sResult!=null) {     alert(sResult + "已經(jīng)超越神的殺戮"); }else{     alert("無名氏已經(jīng)超越神的殺戮"); }

        顯示如下:

        javascript中window的意思是什么

        時間等待與間隔函數(shù):

      • JavaScript setTimeout() 函數(shù)
      • JavaScript clearTimeout() 函數(shù)
      • JavaScript setInterval() 函數(shù)
      • JavaScript clearInterval() 函數(shù)

        1、setTimeout()、clearTimeout()  在指定的時間后調(diào)用函數(shù)

        語法:

      • setTimeout(fun,time);  fun:函數(shù)體或函數(shù)名,time指定時間,單位為毫秒。
      • clearTimeout(id);  取消指定的setTimeout函數(shù)將要執(zhí)行的代碼
          setTimeout(function () {         document.write("隔3秒后觸發(fā)");        }, 3000)    //在3秒后輸出     setTimeout(fun1, 5000);     //在5秒后輸出     function fun1() {         document.write("函數(shù)名的方式5秒后觸發(fā)");     }

        2、setInterval()、clearInterval(value)  在間隔指定的事件后重復(fù)調(diào)用函數(shù)

        語法:

      • setInterval(fun1,time)  fun:函數(shù)體或函數(shù)名,time指定的時間,單位為毫秒。會返回一個值,這個值是統(tǒng)計該函數(shù)的個數(shù)用的,第一個是1,第二個就是2,指明是第幾個setInterval函數(shù)。
      • clearInterval(value)    value:setInterval()函數(shù)返回的值,根據(jù)這個值可以停止setInterval()的重復(fù)。 
      var i = 0;var h = setInterval(function () {     document.write("3秒輸出一次<br/>");     i++;    if (i >= 3) {        clearInterval(h);         document.write("停止輸出");     } }, 3000);

        注意,javascript是單線程的,因此,這個定時函數(shù)實際上是通過插入執(zhí)行隊列的方式來實現(xiàn)。

        如下面的代碼:

      function fn() {    setTimeout(function(){alert('can you see me?');},1000);    while(true) {}  }

        alert();永遠都不會執(zhí)行,因為線程一直被死循環(huán)占用了。

      window.location子對象

        解析URL對象location

        location對象的屬性有:href,protocal,host,hostname,port,pathname,search,hash

              document.write(location.href + "<br/>");        // http://localhost:4889/javascriptTest.html         document.write(location.protocol + "<br/>");    // http:         document.write(location.host + "<br/>");        // localhost:4889         document.write(location.hostname + "<br/>");    // localhost         document.write(location.port + "<br/>");        // 4889         document.write(location.pathname + "<br/>");    // /javascriptTest.html         document.write(location.search + "換行<br/>");  //http://localhost:4889/javascriptTest.html?id=1&name=張三 如果路徑是這樣,則輸出  ?id=1&name=%E5%BC%A0%E4%B8%89         document.write(location.hash);                  //http: //localhost:4889/javascriptTest.html#kk=你好?id=1&name=張三 如果路徑是這樣,則輸出  #kk=你好?id=1&name=張三

        載入新文檔

          location.reload()  重新加載頁面

          location.replace()  本窗口載入新文檔

          location.assign()  本窗口載入新文檔

          location = "http://www.baidu.com"  //跳轉(zhuǎn)到指定網(wǎng)址

          location = "search.html"        //相對路徑跳轉(zhuǎn)

          location = "#top"      //跳轉(zhuǎn)到頁面頂部

        瀏覽歷史

          History()對象的back()與forward()  與瀏覽器的“后退”,"前進"功能一樣。

          history.go(-2);  后退兩個歷史記錄

        瀏覽器和屏幕信息

          navigator.appName  Web瀏覽器全稱

          navigator.appVersion  Web瀏覽器廠商和版本的詳細字符串

          navigator.userAgent  客戶端絕大部分信息

          navagator.platform   瀏覽器運行所在的操作系統(tǒng)

              document.write(navigator.userAgent + "<br/>"); // Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11         document.write(navigator.appName + "<br/>");   //Netscape         document.write(navigator.appVersion + "<br/>"); //5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11         document.write(navigator.platform);             //Win32

      窗口的關(guān)系

          parent == self  只有頂級窗口才返回true

           parent和top屬性允許腳本引用它的窗體的祖先,通常窗體是通過<iframe>元素創(chuàng)建的,可以用來獲取頂級窗口。

      5、event事件對象

        最有用的兩個操作:阻止事件冒泡。有時return false;不管用,這個或許就管用了。

      //IE: window.event.cancelBubble = true;//停止冒泡 window.event.returnValue = false;//阻止事件的默認行為  //Firefox: event.preventDefault();// 取消事件的默認行為   event.stopPropagation(); // 阻止事件的傳播

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號