BOM也叫浏览器对象模型,它提供了很多对象,用于访问浏览器的功能;
window对象是最顶层的对象
window对象有六大属性(document, frames, history,location,navigator,screen),这六大属性本身也是对象
window对象下面的document属性,也是对象,并且document对象下面有五大属性(anchors, forms,images,links,location)
document对象下面的五大属性也是对象
调用
window的属性和方法的调用:window.属性,window.方法()
也可 直接 属性,方法()
如果是某个浏览器独有的属性或者方法,那么在其它浏览器可能会不识别,当做普通变量
confirm("请。。。");//方法返回值为布尔值,如果点击确定,返回true,如果点击取消,就返回false
if(confirm('请选择')){
alert('您按了确定按钮');
} else{
alert('您按了取消按钮');
}
//输入提示框
var box = prompt('请输入一个数字',0);//第一个参数是说明,第二个参数是默认值,返回输入的值
if(box!=null){
alert(box);
}
open('http://www.baidu.com');//新建窗口并打开百度
//跨浏览器的方法
var leftX = (typeof screenLeft=='number')?screenLeft:screenX;
var topY = (typeof screenTop=='number')?screenTop:screenY;
alert(leftX);
alert(topY);
//跨浏览器获取视口(可视范围的页面窗口)
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);
alert(height);
setTimeout("alert('Lee')", 2000)//2秒后执行第一个参数的代码块
function box(){
alert('Lee');
}
setTimeout(box,2000);
setTimeout(function(){alert('Lee');}, 2000);//推荐,扩展性好,封装性好
var box = setTimeout(function(){alert('Lee');}, 2000);
clearTimeout(box);//取消当前超时调用计划
var box = setInterval(function(){alert('Lee');},1000);//间歇调用,可以重复不断的执行
clearInterval(box); //取消调用
//定时器
var num =0;
var max = 5;
var id = null;
function box(){
num++;
document.getElementById('a').innerHTML+=num;
if(num == max){
clearInterval(id);
alert('5秒到了!');
}
}
id = setInterval(box,1000);
//使用超时调用,模拟定时器
var num = 0;
var max = 5;
function box(){
num++;
document.getElementById('a').innerHTML += num;
if(num == max){
alert('5秒到了!');
}else{
setTimeout(box, 1000);
}
}
setTimeout(box, 1000);
function getArgs(){
var args = [];
var qs = location.search.length>0?location.search.substring(1):'';
var items = qs.split('&');
var item = null, name = null, value = null;
for(var i =0; i<items.length; i++){
item = items[i].split('=');
name = item[0];
value = item[1];
args[name] = value;
}
return args;
}
var args = getArgs();
alert(args['id']);
alert(args['search']);
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交