进阶11
变量的生命周期
全局变量,与window一样
函数里面变量:函数执行开始,出生,函数调用结束,死亡
默认作用域消失时,内存被收回;
如果内存被引用着,则不能回收;
var 作用域
就近原则,当前作用域找,可用原型链的伪代码查找
变量提升,var提升到作用域顶部,不要想,先提升
setTimeout(code,time)
setInterval(code,time)当最小化
异步:不等结果,然后回调函数
disabled ,表示元素是被禁用的。
如果这个元素的disabled属性被设置为true,表示元素被禁用,被禁用的属性在页面上通
常会显示灰色文本,它无法响应用户的操作,它也无法得到光标;
<!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">继续</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继承本页面的协议
window.location.href=
window.location=''href可写可不写
location.port端口号
location.hostname获取名称
location.host获取完整的名称包括端口
location.pathname获取路径
location.search获取问号后面的
window.location.hash锚点
location.orgin协议+域名+端口号
window.name,窗口名 a target='frank' _self当前窗口
window.navigator.userAgent获得浏览器版本号,
window.open(url,windowName,feature)
window.opener(打开本窗口的)











网友评论