《JavaScript高級(jí)程序設(shè)計(jì)》筆記(2)

閉包

function createFunctions(){
     var result = new Array();  
    for (var i=0; i < 10; i++){
         result[i] = function(){
             return i;
         };
     }  
    return result; }
//i均為10
function createFunctions(){
     var result = new Array();  
    for (var i=0; i < 10; i++){
         result[i] = function(num){
             return function(){
                 return num; 
            };
         }(i);
     }  
    return result; }
//i為1,2,3…10

BOM

window對(duì)象

在 IE9+、Safari和Firefox 中,outerWidth 和 outerHeight 返回瀏覽器窗口本身的尺寸(無(wú)論是從外層的 window 對(duì)象還是從 某個(gè)框架訪問(wèn))。在Opera中,這兩個(gè)屬性的值表示頁(yè)面視圖容器①的大小。而innerWidth 和innerHeight 則表示該容器中頁(yè)面視圖區(qū)的大小(減去邊框?qū)挾龋?。?Chrome 中,outerWidth、outerHeight 與 innerWidth、innerHeight 返回相同的值,即視口(viewport)大小而非瀏覽器窗口大小。在 IE、Firefox、Safari、Opera 和 Chrome 中,document.documentElement.clientWidth 和 document.documentElement.clientHeight 中保存了頁(yè)面視口的信息。在 IE6中,這些屬性必須在 標(biāo)準(zhǔn)模式下才有效;如果是混雜模式,就必須通過(guò)document.body.clientWidth和document.body. clientHeight 取得相同信息。而對(duì)于混雜模式下的 Chrome,則無(wú)論通過(guò) document.documentElement 還是 document.body 中的 clientWidth 和 clientHeight 屬性,都可以取得視口的大小。

window.open()
setTimeout()、clearTimeout()、setInterval()、clearInterval()
alert()、confirm()和 prompt()

location對(duì)象

location.href = "";

history對(duì)象

history.go()

DOM

  • getAttribute() setAttribute()
  • document.createElement()
  • 父、子節(jié)點(diǎn)
  • document.createTextNode()

DOM擴(kuò)展

HTML5

  • getElementsByClassName()方法
  • classList 屬性

<div class="bd user disabled">...</div>
div.classList.remove("user");

  • innerHTML()
  • scrollIntoView()可以在所有 HTML 元素上調(diào)用,通過(guò)滾動(dòng)瀏覽器窗口或某個(gè)容器元素,調(diào)用 元素就可以出現(xiàn)在視口中。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容