Javascript BOM

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']);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值