您的位置:首页 > Web前端 > JavaScript

JavaScript学习笔记:用JavaScript部分小功能的实现

2014-11-05 21:51 525 查看
定时器:在屏幕打印五秒,到五秒时弹出停止的会话框;

一般用超时调用的这种方法:

var num=0;

var max=5;

function box(){

num++;

if(num==max){

alert("5s is over!!");

}

else(

setTimeout(box,1000);

)

}

setTimeout(box,1000);

但也可以用这种方式实现:

var num=0;

var max=5;

var id=null;

function box(){

num++;

document.getElementById('a').innerHTML +=num;

if(num==max){

clearInterval(id);

alert("5s is OVAR!!!");

}

}

id=setInterval(box,1000);

HTML页面代码很简单,具体如下:

<div id="a"></div>

跨浏览器获取可视化页面窗口

var width = window.innerWidth;

var height = window.innerHeight;

if(typeof width!='number'){

if(document.compatMode=='CSS1Compat'){

width=document.documentElement.clientWidth;

height=document.documentElement.clientHeight;

}

else{

width=document.body.clientWidth;

height=document.body.clientHeight;

}

}

alert(width); //widht\height各浏览器 的值各不相同

alert(height);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: