dom

作用域

//通過函數(shù)分離作用域:局部變量和全局變量 //函數(shù)內(nèi)部的是局部變量,只能在函數(shù)體內(nèi)訪問到,外部無法訪問 //函數(shù)體內(nèi)聲明的變量有:形式參數(shù)和var聲明的變量 function f(x){ var y=2 //x和y都是局部變量 } //函數(shù)執(zhí)行完畢后,函數(shù)體內(nèi)的執(zhí)行環(huán)境被銷毀,不會(huì)將數(shù)據(jù)常駐在內(nèi)存中 f(5) //無法訪問 //console.log(x,y)

function f(){ z=3 //沒有通過var聲明的變量是全局變量 } f() //console.log(z)3

引用類型

//數(shù)據(jù)類型,根據(jù)他們?cè)诓僮鲿r(shí)的不同行為,可以劃分成 //1、基本類型的數(shù)據(jù),也叫基本數(shù)據(jù)類型 單一值的數(shù)據(jù)類型 boolen string number //2、引用類型的數(shù)據(jù),也叫復(fù)合類型數(shù)據(jù),不僅有值還有結(jié)構(gòu), object(object Array,null) //基本類型的數(shù)據(jù),內(nèi)容都比較固定 列如,一個(gè)值最多只需要8個(gè)字節(jié)就足夠存儲(chǔ),因此他們?cè)谫x值時(shí)會(huì)復(fù)制“值”的副本 //而引用類型 例如對(duì)象 不僅有值還有方法 內(nèi)容可能較大 如果賦值時(shí)在單獨(dú)創(chuàng)建值的副本,,就會(huì)顯著占用內(nèi)存,因此他賦值的是對(duì)象的地址 //意味著 著兩個(gè)變量引用了同一個(gè)地址對(duì)應(yīng)的對(duì)象

//基本類型賦值 b=a(傳值操作) //a 1001 78 //b 1002 78

//引用類型賦值 lily=lucy(傳址操作) //lucy 1001 //lily 1001

//區(qū)別是 //基本類型賦值時(shí),內(nèi)存中有倆個(gè)值,互補(bǔ)影響 //引用類型賦值時(shí),內(nèi)存中 ,只有1個(gè)值,誰修改都會(huì)影響到另一個(gè)

BOM

window對(duì)象

//window是BOM頂層對(duì)象,代表瀏覽器打開的當(dāng)前窗口 //并且是javascrtipt的代碼的宿主環(huán)境,js寄生在window中執(zhí)行,頁面中所有的全局變量都是window的屬性

//window對(duì)象除了執(zhí)行js代碼,還用來(腳本化)渲染(操作)當(dāng)前窗口 //作為對(duì)象,提供了屬性和方法,來訪問窗口,現(xiàn)代瀏覽器不允許總是上來就加載彈窗 //一般在按鈕點(diǎn)擊后打開窗口 <input type ="button" value="打開新窗口" onclick="open_win()"> function open_win(){ new_win=window.ope()//打開新窗口 window.alert()//在父級(jí)顯示彈窗 new_win.alert()//在新窗口顯示彈窗 new_win.document.write()//在新窗口頁面顯示 }

<input type ="button" value="關(guān)閉新窗口" onclick="close_win()"> function close_win(){ new_win.close//關(guān)閉新窗口 }

<input type="button" value="移動(dòng)新窗口" onclick="move_win()"> function move_win(){ new_win.moveTo//移動(dòng)窗口 new_win.moveBy//相對(duì)當(dāng)前位置移動(dòng) new_win.focus() //重新獲取焦點(diǎn),顯示窗口 }

function reset_win(){ new_win.resizeTo()//重置固定大小 new_win.resizeBy()//相對(duì)原來增長 new_win.coresize=function(){ new_win.alert()//監(jiān)聽窗口大小改變 } }

onerror

//window對(duì)象的onerror方法(事件)用來監(jiān)聽當(dāng)前頁面的腳本代碼錯(cuò)誤 window.onerror=function(mag,file,line,col){ alert("來自站內(nèi)的錯(cuò)誤提示:"+msg+"\n(換行)"+"第"+line+"行,第"+col+"列") }console.log(x)

innerwidthj和innerheight

console.log(window.innerwidth,window.innerHeight)//網(wǎng)頁尺寸

location對(duì)象

//location對(duì)象訪問地址欄信息 console.log(location) //href屬性---可讀可寫 console.log(location.href)//讀取地址 //重新設(shè)置地址 -跳轉(zhuǎn) 不能返回 //location.href ="http://....."

//地址參數(shù) 一般也稱為查詢字符串 querystr ="?foo=bar&a=1&b=2" //轉(zhuǎn)化成對(duì)象 便于使用 result={foo:"bar" ,a:1,b:2} function geargs(querystr){ var result ={} //一系列計(jì)算 var pairs =querystr.slice(1)//foo=bar&a=1&b=2 //拆分成對(duì) var pairs =str.split("&")//["foo=bar","a=1""b=2] //循環(huán) 分別提取每一對(duì)中的參數(shù)和值的部分 for (var i = 0; i < pairs.length; i++) { pairs[i]; // foo=bar var pos = pairs[i].indexOf("="); var name = pairs[i].slice(0, pos); var value = pairs[i].slice(pos+2); result[name] = value; } return result; }

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="" cid="n35" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> var result = getArgs(location.search);
console.log(result);</pre>

}

<input type="button" value="assign跳轉(zhuǎn)" onclick="assign()">//assign(指定)(跳轉(zhuǎn)) <input type="button" value="replace跳轉(zhuǎn)" onclick="replace()">//replace(跳轉(zhuǎn)) <input type="button" value="reload刷新" onclick="reload()">//reload(刷新) location.assign(跳轉(zhuǎn)地址) location.replace(跳轉(zhuǎn)地址) location.reload(刷新)

返回 返回 go(1)前進(jìn) go(0)刷新 go(-1)返回

?著作權(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),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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