window对象学习1

window对象学习1

BOM浏览器对象模型:是规范浏览器对js语言的支持(js调用浏览器本身的功能)。
BOM的具体实现是window对象
window对象使用学习:
1、window对象不用new,直接进行使用即可,类似Math的使用方式,window关键字可以省略不写。
2、框体方法
alert:警告框 提示一个警告信息,没有返回
confirm:确认框 提示用户选择一项操作(确定/取消)
点击确定 返回true
点击取消 返回false
prompt:提示框, 提示用某个信息的录入或者说收集
点击确定,返回当前用书录入的数据,默认返回空字符串
点击取消,返回null
3、定时和间隔执行方法
setTimeout:指定的时间后执行指定的函数
参数1:函数对象
参数2:时间,单位毫秒。
返回值:返回当前定时器的id
setInterval:每间隔指定的时间执行指定的函数
参数1:函数对象
参数2:时间,单位毫秒。
返回值:返回当前间隔器的id
clearTimeout:用来停止指定的定时器
参数:定时器的id
clearInterval:用来停止指定的间隔器
参数:间隔器的id

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>window对象学习</title>
		<script type="text/javascript">
			//框体方法学习:
			//警告框
			function testAlert(){
				
				var b=window.alert("我是警告框");
				alert("返回警告框的返回值:"+b);
				
			}
			//确认框
			function testConfirm(){
				
				var a=window.confirm("你确定删除?");
				alert("确认框的返回值:"+a);
			}
			//提示框
			function testPrompt(){
				var str=window.prompt("请输入昵称");
				alert("提示框的返回值:"+str);
			}
		/*****************************************************************************/
		var idi;
		var ids;
		//定时执行
		function testSetTimeout(){
			idi=window.setTimeout(function(){
				alert("我是定时执行")
			},3000);
		}
		//间隔执行
		function testSetInterval(){
			ids=window.setInterval(function(){
				alert("我是间隔执行");
			},2000);
		}
		//停止当前的定时方法
		function testClearTimeout(){
			window.clearTimeout(idi);
		}
		function testClerInterval(){
			window.clearInterval(ids);
		}
			
		</script>
	</head>
	<body>
	<hr />
	<input type="button" value="测试警告框"onclick="testAlert();" />
	<input type="button" value="测试确认框"onclick="testConfirm();" />
	<input type="button" value="测试提示框"onclick="testPrompt();" />
	<hr />
	
	<input type="button" value="测试setTimeout--定时执行"onclick="testSetTimeout();" />
	<input type="button" value="测试setInterval--间隔执行"onclick="testSetInterval();" />
	<input type="button" value="测试clearTimeout--停止指定的定时器"onclick="testClearTimeout();" />
	<input type="button" value="测试clearInterval--停止指定的间隔器"onclick="testClerInterval();" />
	
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值