文件对象:
代表当前HTML对象,是由<body>标签组构成的,对每个HTML文件会自动建立一个文件对象。
格式:
document.属性
document.方法(参数)


文件对象的事件处理程序:
onClick onDbClick onKeyDown onKeyPress onKeyUp onMouseDown onMouseOver
<Script> document.bgColor = "white"; document.fgColor = "black"; document.linkColor = "red"; document.alinkColor = "blue"; document.vlinkColor = "purple"; </Script> 测试文件对象的颜色属性:<BR> <A HREF="http://www.google.com.hk">Google</A>
<Script> var update_date = document.lastModified; var formated_date = update_date.substring(0,10); document.write("本网页更新日期:" + update_date + "<BR>") document.write("本网页更新日期:" + formated_date) </Script>
锚点对象:
这是虾米啊

网页中的锚点均会被自动看作锚点对象,并依顺序,分别表示为document.anchors[0],document.anchors[1]...
定义锚点对象的格式:
字串.anchor(属性)

链接对象:
网页中的链接均会被自动看作链接对象,并依顺序,分别表示为document.links[0],document.links[1]...
定义链接对象的格式:
字串.link(属性)

链接对象的方法:
handleEvent(事件)
激活对某事件的处理程序。
链接对象的事件处理程序:
onClick onDbClick onKeyDown onKeyPress onKeyUp onMouseDown onMouseUp onMouseOver onMouseOut
<Script> function linkGetter() { msgWindow = open('','','width=250,height=200') msgWindow.document.write("共有" + document.links.length + "个搜索引擎") for (var i = 0; i < document.links.length; i++) { msgWindow.document.write("<LI>"+document.links[i]) } } </Script> 常用的搜索引擎:<BR> <A HREF="http://www.Google.com.hk/">Google</A> <A HREF="http://www.Baidu.com/">百度</A> <A HREF="http://cn.bing.com/">必应</A><BR> <INPUT TYPE="button" VALUE="网址一览" onClick=linkGetter()>
框架对象:
可以被窗口中的框架引用的对象,具有窗口对象的属性和方法。
格式:
top.frameName|frames[n].属性|方法
parent.frameName|frames[n].属性|方法
/* -------- frameset.htm -------- */
<Script> document.title = "框架组页"; var usrID = "来宾"; </Script> <FRAMESET COLS="20%,80%"> <FRAME SRC="menu.htm" NAME=leftFrame> <FRAMESET ROWS="10%,90%"> <FRAME SRC="usrInfo.htm" NAME=upFrame> <FRAME SRC="welcome.htm" NAME=downFrame> </FRAMESET> </FRAMESET>
<!-------- menu.htm -------->
<HEAD> <TITLE>导航页</TITLE> <STYLE>A{text-decoration:none}</STYLE> </HEAD> <BODY> <CENTER> <A HREF="login.htm" TARGET="downFrame">会员登录</A><BR> <A HREF="hot.htm" TARGET="downFrame">热门优惠</A><BR> <A HREF="welcome.htm" TARGET="downFrame">回 首 页</A> <BR> </CENTER> </BODY>
/* -------- usrInfo.htm -------- */
<Script> document.title = "用户信息"; var bye = "欢迎有空常来..." document.write ("<MARQUEE>亲爱的<FONT COLOR='gray'><U>",top.usrID,"</U></FONT>会员,欢迎您的光临!</MARQUEE>"); </Script>
/* -------- login.htm -------- */
<Script> document.title = "用户登录"; function login() { top.usrID = document.loginForm.usr.value; top.upFrame.location = "usrInfo.htm"; } </Script> <HTML> <FORM NAME="loginForm"> 请输入您的大名: <INPUT TYPE="text" NAME="usr"> <INPUT TYPE="button" VALUE="填写完毕" onClick=login()> </FORM> </HTML>
防止直接链接:
/* -------- hot.htm -------- */
<Script> document.title = "热门优惠"; if (top.usrID == null) { location = "frameset.htm"; } </Script> 今日优惠: <LI>超级豪华大比萨。(原价$550,今天只要$450) <LI>海鲜大比萨。(原价$550,今天只要$450)
检查是否使用框架:
<!-------- welcome.htm -------->
<HEAD> <TITLE>首页</TITLE> <STYLE>A{text-decoration:none}</STYLE> <Script> if (top.frames.length == 0) { location = "frameset.htm"; } if (top.frames.length > 0) { location = "frameset.htm"; } </Script> </HEAD> <CENTER> 欢迎光临<H1> <FONT COLOR="green" FACE="arial"> My PIZZA</FONT></H1> </CENTER>
――――――――――――――――――――<这是不太华丽的分割线>――――――――――――――――――――
表单对象:
文件对象的子对象,Javascript的runtime engine自动为每一个表单建立一个表单对象。
格式:
document.forms[索引].属性
document.forms[索引].方法(参数)
document.表单名称.属性
document.表单名称.方法(参数)
