第二章 JavaScript操作BOM对象
BOM模型:BOM:浏览器对象模型(Browser Object Model)
核心:window
window对象
常用属性:history:有有关客户访问过url的信息
location:有关当前url的信息
常用的方法:prompt()
alert()\
confirm()
close()
open()
setTimeout()
setinterval()
区别:
alert( ):一个参数,仅显示警告对话框的消息,无返回值,不能对脚本产生任何改变
prompt( ):两个参数,输入对话框,用来提示用户输入信息,常用于收集用户关于特定问题而反馈的信息
confirm( ):一个参数,确认对话框,显示提示对话框的消息,一般情况下和if else组合使用
open()方法
语法:window.open("弹出窗口的url","窗口名称","窗口特征”)
属性名称
|
说 明
|
height、width
|
窗口文档显示区的高度、宽度。以像素计
|
left、top
|
窗口的x坐标、y坐标。以像素计
|
toolbar=yes | no |1 | 0
|
是否显示浏览器的工具栏。黙认是yes
|
scrollbars=yes | no |1 | 0
|
是否显示滚动条。黙认是yes
|
location=yes | no |1 | 0
|
是否显示地址地段。黙认是yes
|
status=yes | no |1 | 0
|
是否添加状态栏。黙认是yes
|
menubar=yes | no |1 | 0
|
是否显示菜单栏。黙认是yes
|
resizable=yes | no |1 | 0
|
窗口是否可调节尺寸。黙认是yes
|
titlebar=yes | no |1 | 0
|
是否显示标题栏。黙认是yes
|
fullscreen=yes | no |1 | 0
|
是否使用全屏模式显示浏览器。黙认是no。处于全屏模式的窗口必须同时处于剧院模式
|
history对象、location对象
history对象:back()返回操作
forward()
go()
特别说明:history.back等价于history.go(-1)
history.forward()等价于history.go(1)
location对象常用属性:host
hostname
href 刷新操作
常用方法:reload()
replace()
document对象:
常用属性:referrer:返回载入当前文档的URl
url:返回当前文档的url
常用属性的语法:document.referrer
document.URL
常用方法:getElementByid()
getEmentsByName()
getElementsByTagName()
常用语法:document.getElementByid()
document.getEmentsByName()
document. getElementsByTagName()
document.write()
JavaScript内置对象
String
Array
Data:getData():返回一个月中的某一天(1-31)
getDay():返回星期中的某一天(0-6)
getHours()返回小时数(0-23)
getMinutes()返回分钟(0-59)
getSecounds()返回秒(0-59)
getMonth()返回月(0-11)
getFullYear()返回年,其值为4位数
getTime()返回某一时刻,毫秒
Math:ceil对数进行上舍入
floor()对数进行下舍入
round()把数四舍五入为接近的数
random()返回0-1之间的随机数
定时函数:setTimeout()
语法:setTimeout("调用的函数",等待的毫秒数)
<input name=“btn" type="button" value="显示提示消息" onclick="timer()" />
function timer(){
var time=setTimeout("alert('3s之后才弹出')",3000);
}
定时函数2
setInterval()
语法:setInterval("调用的函数",间隔的毫秒数)
var myTime=setInterval("showTime()", 1000 );
setTimeout()在等待指定时间后执行函数,且只执行一次
setInterval()是每隔固定时间后执行一次函数,循环执行
清除函数
clearTimeout()
语法:clearTimeout(setTimeOut()返回的ID值)
var myTime=setTimeout("disptime() ", 1000 );
clearTimeout(myTime);
clearInterval ()
语法clearInterval(setInterval()返回的ID值)
var myTime=setInterval("disptime() ", 1000 );
clearInterval(myTime);