進(jìn)階11
變量的生命周期
全局變量,與window一樣
函數(shù)里面變量:函數(shù)執(zhí)行開始,出生,函數(shù)調(diào)用結(jié)束,死亡
默認(rèn)作用域消失時,內(nèi)存被收回;
如果內(nèi)存被引用著,則不能回收;
var 作用域
就近原則,當(dāng)前作用域找,可用原型鏈的偽代碼查找
變量提升,var提升到作用域頂部,不要想,先提升
setTimeout(code,time)
setInterval(code,time)當(dāng)最小化
異步:不等結(jié)果,然后回調(diào)函數(shù)
disabled ,表示元素是被禁用的。
如果這個元素的disabled屬性被設(shè)置為true,表示元素被禁用,被禁用的屬性在頁面上通
常會顯示灰色文本,它無法響應(yīng)用戶的操作,它也無法得到光標(biāo);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<select name="定義時間" id="setTime">
<option value="1" selected>1分鐘</option>
<option value="5">5分鐘</option>
<option value="10">10分鐘</option>
</select>
<button id="star">開始</button>
<button id="pause" disabled="true">暫停</button>
<button id="resume" disabled="true">繼續(xù)</button>
<div id="show">
</div>
</head>
<body>
<script type="text/javascript">
var timeLeft=0;
var timeOutId;
function showTime(){
show.innerText=timeLeft;
if(timeLeft===0){
return
}
timeLeft-=1;
timeOutId=setTimeout(showTime,1000)
}
star.onclick=function(){
pause.disabled=false;
if(timeOutId){
window.clearTimeout(timeOutId)
}
timeLeft=document.getElementById('setTime').value;
timeLeft=parseInt(timeLeft)*60
showTime()
}
pause.onclick=function(){
pause.disabled=true;
resume.disabled=false;
window.clearTimeout(timeOutId)
}
resume.onclick=function(){
pause.disabled=false;
resume.disabled=true;
showTime()
}
</script>
</body>
</html>
bom
window.history.back
window.history.forword
window.history.go(-1)后退
//www.baidu.com繼承本頁面的協(xié)議
window.location.href=
window.location=''href可寫可不寫
location.port端口號
location.hostname獲取名稱
location.host獲取完整的名稱包括端口
location.pathname獲取路徑
location.search獲取問號后面的
window.location.hash錨點(diǎn)
location.orgin協(xié)議+域名+端口號
window.name,窗口名 a target='frank' _self當(dāng)前窗口
window.navigator.userAgent獲得瀏覽器版本號,
window.open(url,windowName,feature)
window.opener(打開本窗口的)