• 文件对象:

    代表当前HTML对象,是由<body>标签组构成的,对每个HTML文件会自动建立一个文件对象。

    格式:

    document.属性
    document.方法(参数)

  • 文件对象的属性:

    linkColor 设置超链接的颜色
    alinkColor 作用中的超链接的颜色
    vlinkColor 链接的超链接颜色
    links 以数组索引值表示所有超链接
    URL 该文件的网址
    anchors 以数组索引值表示所有锚点
    bgColor 背景颜色
    fgColor 前景颜色
    classes 文件中的class属性
    cookie 设置cookie
    domain 指定服务器的域名
    formName 以表单名称表示所有表单
    forms 以数组索引值表示所有表单
    images 以数组索引值表示所有图像
    layers 以数组索引值表示所有layer
    embeds 文件中的plug-in
    applets 以数组索引值表示所有applet
    plugins 以数组索引值表示所有插件程序
    referrer 代表当前打开文件的网页的网址
    tags 指出HTML标签的样式
    title 该文档的标题
    width 该文件的宽度(px)
    lastModified 文件最后修改时间
  • 文件对象的方法:

    captureEvents(事件) 设置要获取指定的事件
    close() 关闭输出字符流,强制显示数据内容
    getSelection() 取得当前选取的字串
    handleEvent(事件) 使事件处理器生效
    open([mimeType,[replace]]) 打开字符流
    releaseEvents(事件类型) 释放已获取的事件
    routeEvent(事件) 传送已捕捉的事件
    write(字串) 写字串或数值到文件中
    writeln(字串) 分行写字串或数值到文件中(<pre>..</pre>)
  • 文件对象的事件处理程序:

    onClick onDbClick onKeyDown onKeyPress onKeyUp onMouseDown onMouseOver

例1:
<Script>

document.bgColor = "white";
document.fgColor = "black";
document.linkColor = "red";
document.alinkColor = "blue";
document.vlinkColor = "purple";

</Script>

测试文件对象的颜色属性:<BR>

<A HREF="http://www.hubert.idv.tw">文哥网路技术学习网</A>

例2:
<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(属性)

  • 锚点对象的属性:

    name 锚点名称
    text 锚点字串
 
  • 链接对象:

    网页中的链接均会被自动看作链接对象,并依顺序,分别表示为document.links[0],document.links[1]...

    定义链接对象的格式:

字串.link(属性)

  • 链接对象的属性:

    hash URL中的锚点名称
    host 主机域名或IP地址
    hostname URL中的host+port
    href 完整的URL字串
    pathname URL中path部分
    port URL中端口部分
    protocol URL中通讯协议部分
    search URL中查询字串部分
    target 代表目标的窗口
    text 表示A标签中的文字
    x 链接对象的左边界
    y 链接对象的右边界
  • 链接对象的方法:

    handleEvent(事件)
    激活对某事件的处理程序。

  • 链接对象的事件处理程序:

    onClick onDbClick onKeyDown onKeyPress onKeyUp onMouseDown onMouseUp onMouseOver onMouseOut

例1:
<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.yam.org.tw/">蕃薯藤</A>
<A HREF="http://www.kimo.com/">奇摩</A>
<A HREF="http://chinese.yahoo.com/">雅虎</A>
<A HREF="http://gais.cs.ccu.edu.tw/">盖世</A>
<A HREF="http://www.openfind.com.tw/">网擎</A>
<A HREF="http://www.dreamer.com.tw/">梦想家</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>

  • 防止直接链接:

例:
<Script> /* -------- hot.htm -------- */

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>



ExtJS教程- Hibernate教程-Struts2 教程-Lucene教程