1.bom(浏览器对象模型)总结
所有的浏览器都有5个对象
window:窗口
location:定位信息 (地址栏)
history:历史
window对象详解:
如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,
并为每个框架创建一个额外的 window 对象。
常用的属性:
通过window可以获取其他的四个对象
window.location 等价域 location
window.history 等价于 history
...
常用的方法
消息框
alert("...."):警告框
confirm("你确定要删除吗?"):确定框 返回值:boolean
prompt("请输入您的姓名"):输入框 返回值:你输入的内容
定时器
设置定时器
setInterval(code,毫秒数):周期执行
setTimeout(code,毫秒数):延迟多长事件后 只执行一次.
例如:
setInterval(showAd,4000);
serInterval("showAd()",4000);
清除定时器
clearInterval(id):
clearTimeout(id):
打开和关闭
open(url):打开
location:定位信息
常用属性:
href:获取或者设置当前页面的url(定位信息)
location.href; 获取url
history:历史
back();后退
forward():向前
★go(int)
go(-1) 相当于 back()
所有的浏览器都有5个对象
window:窗口
location:定位信息 (地址栏)
history:历史
window对象详解:
如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,
并为每个框架创建一个额外的 window 对象。
常用的属性:
通过window可以获取其他的四个对象
window.location 等价域 location
window.history 等价于 history
...
常用的方法
消息框
alert("...."):警告框
confirm("你确定要删除吗?"):确定框 返回值:boolean
prompt("请输入您的姓名"):输入框 返回值:你输入的内容
定时器
设置定时器
setInterval(code,毫秒数):周期执行
setTimeout(code,毫秒数):延迟多长事件后 只执行一次.
例如:
setInterval(showAd,4000);
serInterval("showAd()",4000);
清除定时器
clearInterval(id):
clearTimeout(id):
打开和关闭
open(url):打开
close():关闭
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="打开一个页面" οnclick="openA()" />
</body>
<script type="text/javascript">
function openA(){
open("js.html");//用于打开一个页面 参数为路径
}
alert("你好吗"); //警告框
var flag=confirm("你确定我是个好人吗"); //确定框
if(flag){
alert("回答错误!") //确定则返回值是true,取消则返回值是false
}else{
alert("回答正确")
prompt("请输入你的名字:");//输入框 返回值是你输入的名字
}
</script>
</html>
/
location:定位信息
常用属性:
href:获取或者设置当前页面的url(定位信息)
location.href; 获取url
location.href="...";设置url 相当于 a标签
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="获取当前页面的地址信息" οnclick="getUrl()"/>
<input type="button" value="设置当前页面的地址" οnclick="setUrl()"/>
</body>
<script type="text/javascript">
function getUrl(){
var url=window.location.href;//获取当前页面的地址
alert(url);
}
function setUrl(){
window.location.href="https://www.baidu.com" //相当于a标签 超链接标签
}
</script>
</html>
//
history:历史
back();后退
forward():向前
★go(int)
go(-1) 相当于 back()
go(1) 相当于 forward()
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
这里是a页面
<br />
<a href="b.html" style="text-decoration: none;">点击跳转</a><br />
<input type="button" value="前进" οnclick="goForward()"/>
</body>
<script type="text/javascript">
function goForward(){
history.go(1);//或者是history.forward();
//history.forward();
}
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
这里是b页面<br />
<input type="button" value="后退" οnclick="goBack()"/>
</body>
<script type="text/javascript">
function goBack(){
history.go(-1); //或者是history.back();
//history.back();
}
</script>
</html>