About Etext Wizard

EtextWizard

目录：

一、关于Etext Wizard:

  1. 软件开发目的及软件用途
  2. 软件的主要功能
  3. 软件的安装及卸载
  4. 软件的注册
  5. 软件的下载地址

二、“北极星工作室”的其他软件：

三、我的主页及联系方式：
一、关于Etext Wizard: Top
1.软件开发目的及软件用途 Top
相信各位在上网一段时间后，硬盘里一定积攒了大量的电子文本，如：
技巧集锦、教程、技术文章、编程指南、小说、散文、传记等等，这些
精彩文件平时大量占用你的硬盘空间，一到用的时候，怎么也找不到；
读起来也很费力，一部《三国》你至少要打开一百二十个文件；而且
第二天也找不到昨天读到那里了，你说急人不急人！
   终于有一天想把他们作成帮助文件，但是，面对某个目录下的几千个
文本文件，才发现所谓的“所见即所得”的帮助文件制作软件竟然要
一个又一个地“手工重复劳作”........
  我曾经用Help&Manual手工作了一个包含两千多条Delphi技巧的帮助文件，
历时两三周终于完成，可是...手抽筋，眼发晕，食欲不振.......
  有时，真的希望有人把我想要的文本全处理好再放到网上，可是...
  面对网上成兆亿的文本难道只有手工处理吗？
  由此，萌发了我的软件开发方向：电子文档处理。

“把繁重而又重复乏味的工作全部交给电脑去做吧！
    人的智慧在于告诉它应该怎么做！”
                                —xxx如是说。

2.软件的主要功能 Top

                功能
                 | 简介

                Txt->Help
                 | 文本文件转帮助文件，支持UNIX格式的TXT，自动添加标题、目录、索引。

                Txt->Html
                 | 文本文件转网页，自动处理URL&EMAIL

                Txt->Chm
                 | 文本文件转网页帮助文件，自动添加目录、索引、
                前页、后页等

                Html->Txt
                 | 网页文件转文本，转换完成比较干净彻底
                （可处理&nbsp;等），支持部分ASP文件。

                Html->Chm
                 | 网页文件转网页帮助文件，自动添加目录、索引。

                VBcode->Html
                 | VB源程序转为网页文件便于浏览。

                FileRenamer
                 | 批量文件改名，可预览结果，众多实用选项。

                Index Maker
                 | 对一个或多个目录下的所有或部分文件作索引，
                自动提取网页的<Title>作为标题，自动提取
                TXT第一行作为标题，多种输出格式。

                Dir Maker
                 | 批量目录建造。 *

                Title Editor
                 | 文本文件的标题编辑器及文件预览器。*

                Find&Replace
                 | 批量文件字符串查找替换器
                *

                Big5->GB

       注解：带*的项目尚未最终完成

3.软件的安装及卸载 Top

运行环境： MS win95;win98;win2000. win98以前的版本运行需要VB5.0
          的链接库文件MSVBVM50.DLL。

安装：

直接运行完全安装版即可（建议初次安装使用完全安装版）；
如果你以前安装过EtextWizard，直接下载新版本的主执行文件
EtextWizard.exe覆盖原来的即可。

卸载：

运行“控制面版”的“添加和删除程序”，找到“电子文档处理器”，
  选“卸载”，再依屏幕操作即可。

4.软件的注册 Top

本软件为“共享软件”，即“先试后买”的软件。

由于目前正处于测试阶段，故软件价格待定。

5.软件的下载地址:

本软件将会不定期更新版本，请留意！

http://dadao.net/pub/guohua99/softdown.htm

二、“北极星工作室”的其他软件： Top

TextVampire(网络即时贴) v1.0：Top
浏览文本或网页时，随时把你喜欢的文字很方便地存成.Txt文件。
你要做的只是选好文本，再按一下CTRL-C，这时，点击“网络即时贴”的
粘贴并生成文本文件”钮，TextVampire会自动截取所选文本的第一行（非空）
作为文件名保存起来，方便你将来收集整理、查找；同时也简化了你的击键次数。

http://dadao.net/pub/guohua99/softdown.htm

三、我的主页及联系方式： Top

我的主要站点：

http://dadao.net/pub/guohua99/
 (北极星书库)

(虚拟域名：http://fengguoguohua.yeah.net/)

http://fengguohua.myrice.com/
 (北极星软件库)

http://go.163.com/~guohua99/(电子文档处理器)

镜像站点：

http://members.xoom.com/fengguohua/

http://guohua99.363.net/

eMail:

fengguohua@hotmail.com

警告：Top

对重要文件请先作好备份，以免造成不必要的损失；
用户试用此软件的同时由用户个人承担试用此软件的一切风险，如用户不接受
此项要求请马上把本程序从你的硬盘删除； TXT转HELP结束后，程序会自动删除
已处理过的目录下的所有RTF文件，请在运行前
检查该目录下是否有重要的RTF文件，请作好备份。
请不要使用本软件制作非法电子出版物，否则一切后果由制作人自行承担，与本软件作者无关。
请不要修改本软件的版权信息（包括随软件发布的一切文档），否则作者将保留追究其法律责任的权利。
在不修改作者版权信息及保证软件完整性的前提下，任何个人或组织可随意发布或试用本软件的免费共享版，
但不得对本软件做任何逆向工程（指反汇编、反编译，公布注册码、散发正式版等）。
本文档中所指“程序”或“本程序”均指EtextWizard(中文名：电子文档处理器)。

注：MS,Windows Help(hcw.exe,hcrtf.exe),Html Help(hhw.exe,hhc.exe)的版权均归美国微软公司所有。

All Rights Reserved, Fengguohua of North Star, 2000-05-03

Top


script

JAVASCRIPT语言教程

第 一 章: | ·什麽是 JavaScript?
 | ·执行 JavaScript scripts
 | ·将scripts 语法嵌入HTML文件之中
 | ·第一个函数
 | ·输入型元件
 | ·日期功能 -- 最後修改期
第 二 章: | ·状态栏 (statusbar)显功能
 | ·日期物件
 | ·随数的产生
 | ·开启新窗囗
第 三 章: | ·框 架 (frames) 的 运 用
第 四 章: | ·状态栏(statusbar)
 | ·setTimeout 函 数
 | ·设计一个跑马灯 (scroller)
第 五 章: | ·数组(Arrays)的设计
 | ·如何清除视窗中的文件 (document)
 | ·"前进键" (Forward) 和"倒退键" (Back)的设计
第 六 章: | ·同时载入两个框架 (frames)
 | ·利用链结开新视囗
 | ·运算符
第 七 章: | ·输入表格(forms)的确认动作
 | ·送出表格(form)的内容
 | ·如何设定"内定值"

JavaScript的对象 | JavaScript的对象属性
JavaScript的方法 | JavaScript的事件
JavaScript的语法 | JavaScript的保留字
潇逸天地 制作


Get Update News

Update Link:
http://dadao.net/pub/guohua99/softdown.htm

程序会经常更新，请登陆网站以得到最新版本。如有任何意见和建议也请给我发Email。

我的Email地址： fengguohua@hotmail.com。


Goto EtextWizard's Homepage

My Homepage:
http://dadao.net/pub/guohua99/

这里有许多已经经过我的“电子文档处理器”处理过的Windows帮助文件或Windows HtmlHelp格式的小说、传记等作为范本供大家参考。


事件处理

以下的事件可由 JavaScript 发生:

  • onBlur
  • onChange
  • onClick
  • onFocus
  • onLoad
  • onMouseOver
  • onSelect
  • onSubmit
  • onUnload

    onBlur event handler

    A blur event occurs when a text or textArea field on a form loses focus. The onBlur event handler executes JavaScript code when a blur event occurs.

    Applies to

    selection, text, textArea

    Examples

    xxx Examples to be supplied.

    onChange event handler

    A change event occurs when a selection, text, or textArea field loses focus and its value has been modified. The onChange event handler executes JavaScript code when a change event occurs.

    Use the onChange event handler to validate data after it is modified by a user.

    Applies to

    selection, text, textArea

    Examples

    xxx Examples to be supplied.

    onClick event handler

    For button or radioButton, JavaScript code to run when a button is clicked. For checkbox, JavaScript code to run when user checks or unchecks an item.

    Applies to

    button, checkbox, radioButton, link, reset, submit

    Examples

    For example, suppose you have created a JavaScript function called compute(). You can execute the compute() function when the user clicks a button by calling the function in the onClick event handler, as follows:

    <INPUT TYPE="button" VALUE="Calculate" onClick="compute(this.form)">

    In the above example, the keyword this refers to the current object; in this case, the Calculate button. The construct this.form refers to the form containing the button.

    For another example, suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to dynamically specify a value for the HREF attribute of the anchor, as shown in the following example:

    <A HREF=""
   onClick="this.href=pickRandomURL();"
   onMouseOver="window.status='Pick a random URL'; return true">
Go!</A>

    In the above example, the onMouseOver event handler specifies a custom message for the Navigator status bar when the user places the mouse pointer over the Go! anchor. As this example shows, you must return true to set the window.status property in the onMouseOver event handler.

    onFocus event handler

    Executed when input focus enters the field, either by tabbing in or by clicking but not selecting in the field.

    Applies to

    selection, text, textArea

    Examples

    xxx Examples to be supplied.

    onLoad event handler

    A load event occurs when Navigator finishes loading a window or all frames within a FRAMESET. The onLoad event handler executes JavaScript code when a load event occurs.

    Use the onLoad event handler within either the <BODY> or the <FRAMESET> tag, for example, <BODY onLoad="...">.

    Applies to

    document, window

    Examples

    xxx Examples to be supplied.

    See also

    onUnload event handler

    onMouseOver event handler

    Executes when the mouse pointer is over an object. You must return true if you want to set the window.status property with the onMouseOver event handler.

    Applies to

    link

    Examples

    By default, the HREF value of an anchor displays in the status bar at the bottom of the Navigator when a user places the mouse pointer over the anchor. In the following example, the onMouseOver event handler provides the custom message "Click this if you dare."

    <A HREF="../../tppmsgs/msgs0.htm#42" tppabs="http://home.netscape.com/" onMouseOver="window.status='Click this if you dare!'; return true"> Click me</A>

    See onClick for an example of using onMouseOver when the anchor HREF attribute is set dynamically.

    onSelect event handler

    A select event occurs when a user selects some of the text within a text or textArea field. The onSelect event handler executes JavaScript code when a select event occurs.

    Applies to

    text, textArea

    Examples

    xxx Examples to be supplied.

    onSubmit event handler

     Specifies the JavaScript code to run when a user attempts to submit a form. Return true to allow the form to be submitted; return false to prevent the form from being submitted.

    Applies to

    form

    Examples

    In the following example, the onSubmit event handler evaluates the data being submitted to test if it is legal. If the data is legal, the form is submitted; otherwise, the form is not submitted.

    form.onSubmit=
"if badFormData(this.form) {
    return false;
} else {
    return true;
}"

    onUnload event handler

    An unload event occurs when you exit a document. The onUnload event handler executes JavaScript code when an unload event occurs.

    Use the onUnload event handler within either the <BODY> or the <FRAMESET> tags, for example, <BODY onUnload="...">.

    Applies to

    document, window

    Examples

    xxx Examples to be supplied.

    See also

    onLoad event handler

    回主目录


JavaScript 简介 ─ 第 1 集

JAVASCRIPT

JavaScript 简介
 第 1 集

JavaScript 是什麽？

JavaScript 是一种新的描述语言，此一语言可以被箝入 HTML 的文件之中。

透过 JavaScript 可以做到回应使用者的需求事件 (如： form 的输入) 而不用任何的网路

来回传输资料，所以当一位使用者输入一项资料时，它不用经过传给伺服端 (server)

处理，再传回来的过程，而直接可以被客户端 (client) 的应用程式所处理。你也可

以想像成有一个可执行程式在你的客端上执行一样！目前已有一些写好的程式在

Internet 上你可以连过去看看，以下有一些计算器的例子，在 Nescape 上。

JavaScript 和 Java 很类似，但到底并不一样！ Java 是一种比 JavaScript 更复杂

许多的程式语言，而 JavaScript 则是相当容易了解的语言。JavaScript 创作者

可以不那麽注重程式技巧，所以许多 Java 的特性在 Java Script 中并不支援。

如需相关的更多资讯，可以去读读 Netscape 的有关 Netscape JavaScript 之介绍。

如何执行 JaveScript？

JavaScript 如何执行呢？

Netscape 2.0 beta 3 版以上，就可以执行 JavaScript 的功能了，我们测试过至少

beta 3 版以上可以，或许 beta 2 版就已经有此功能了（猜的）。但目前为止，

除了 Netscape 外，似乎尚没有其他种类的 WWW 浏览器有此一功能。不过，

资讯科技变化脚步是很快的，也许说著说著就有一大堆出来了。

如果你没有 Netscape Navigator 2.0 的话，建议去取得该程式。目前最新版是

Netscape 2.01 版！而 Netscape 3.0 beta4 版都出来了 呢！

范例 1：

以下我们就以一些例子来告诉你如何将 JavaScript 写在 HTML 文件中，并且体会

一下新语言的特性，我们从第一个例子开始：如何用 JavaScript 印出一串文字至

HTML 文件中：

<html>

<head>

My first JavaScript!

</head>

<body>

<br>

This is a normal HTML document.

<br>

  <script language="LiveScript">

    document.write("这是以 JavaScript 印出的!")

  </script>

<br>

Back in HTML again.

</body>

</html>

如果你使用的 WWW 浏览器是 Netscape 2.0 beta 3 以上版本的话，那你就可以

看到相关的结果，而如果你的浏览器并非是可以支援 JavaScript 的话，那看起

来就会有一些怪怪的了，以上范例的结果如下：

This is a normal HTML document.
这是以 JavaScript 印出的!
Back in HTML again.

此一范例并没有太大的用处，它只是要告诉你如何使用script的标签，并

如何将它置於 HTML 的文件之中而已，这个新的标签你可以特它放在文件

中的任何地方。

范例 2：

接下来下一个例子所要介绍的是有关函数 (function) 的使用。请放心，函数并

非很难懂的东西，但它却相当有用。函数通常是在 HTML 文件中 部份被呼叫，而理所当然地，它最好事先被宣告并放在 HTML 文件中 的部份。好让在 版或无法读取 JavaScript 的浏览器读到，而误会了意思！
如果你是使用 Netscape 2.0 beta 3 以上的浏览器，那以上 JavaScript 语法部份

的结果如下，你可以试著按按钮看看有何结果产生！

在范例 2 中，将会产生一个按钮，当你用滑鼠去按它的时候，应该会出现

一个视窗上面有“嗨! 你好＂的字串，如何？不错吧！这个结果是如何产生

的呢？首先，在 的 input type ="button".....＞将产生一个接钮。然後，你可以

在後面看到 'onClick' 的指令，这就是告诉浏览器，当该按钮被按时，应会执行

onClick 後的函数 'pushbutton()'，而这个函数在刚刚程式被载入时就已安放在

记忆体中了！请注意，在这个函数中我们用到了个新东西─ alert 的 method，

是 JavaScript 事先定义好的，它会以对话视窗产生内涵的讯息，并有一"确定"

(OK)的按钮。 JavaScript 定义了许多的 method，你可以连至 Netscape 公司去

获取较完整的讯息。我想这些 method 在不久的将来会有长长的一串可以够你

学的，不过目前的 method 也已经可以做出相当多东西了！

接著下个例子将告诉你如何由一个输入型表格中读入使用者的输入资料，

事实上，这也是加入个函数就可以达成的。

范例 3：

Please enter your name:
现在你可以试试结果如何：

请输入你的名字：

在这个例子中又有新的东西了。首先，让我们注意一下，在语法中的注解部分

( 的 WWW 浏览器因为不认识这些函数而产生错误。它的顺序应 该为 先，接著为注解的开头 另外要注意的一点是，语解尾那一行的开头双斜线 "//" ，不可以省略，它代表了

JavaScript 的注解，若省略了的话， -＞之前的字会被误认为是 JavaScript 的指令。

这个例子可以让使用者输入一段文字，然後再输入完毕後经由 "onBlur" 事件函数侦知，於是呼叫 Getname(Str)这个函数来加以取得输入字串，

并将它显示在对话视窗上！函数 Getname(this.value) 中的 "this.value" 是你在文

字输入格式中所输入的值。

范例 4：：

这个范例更是帅了！我们在 HTML 文件档完成了以後，常会加上一行文件

最後修改的日期，现在你可不用担心每次都要去改或是忘了改了。你可以

很简单的写一个如下的描述语法程式，就可以自动的为你每次产生最後修

改的日期了：

This is a simple HTML- page.

Last changes:
以上的 document.lastModified 参数在 Netscape 2.0 beta 2 版时是被写成

documeut.lastmodified 的，然而，之後的版本就改为 document.lastModified，

所以注意一下 ；JavaScript 本身是会区分大小写的， lastmodified 与 lastModified

在它看来是不同的结果。

最後，在这一部分结束之前，要提醒你一点，像范例 4 ，的用法并非每一部

机器都是一样的，例如：PC 上跑得很正确的，在工作站上不一定会有相同的

结果，所以，或许你仍得测一测不同机器的结果才会有所定论。当然，这一切

是因为 JavaScript 还正在发展的原因，最新的讯息还是得去拜访一下Netscape

公司才知道。也许你也不用奇怪，当你隔周再来访时，JavaScript 可能又作了

相当大的改变了呢！

回主目录


JavaScript 简介 ─ 第 2 集

JavaScript 简介
 第 2 集

范例 5：

在这一部分首先要为你展示的 JavaScript 特性是将你的滑鼠移到这个不同颜色

的连结上面，此时看看浏览器下的状态列有何结果。然後这样的功能我们可以

与 JavaScript 的功能相结合。好，现在再将你的滑鼠移到本处不同颜色的连结上

面，你应该会发现有一个视窗出现，是吧？！如何！怎麽做到的呢？以下就是

这一个连结的作法：

<a href="tpage.htm" onMouseOver="window.status='Just another stupid link...'; return true">
在这儿你只要在传统 <a> 的标签中加入 onMouseOver 的 method，就可达成你要的

效果了。这里的 window.status 是用来让你可以在 WWW 浏览器的状态列上显示

一些讯息用的。在语法中，你可以看到讯息部分是用 ' 括起来的部分，而非以 " 括

起来，在讯息部分结束之後，必须加上 ; return true。

好了，利用以上的特性可以很简单的完成第二个连结的例子！相当简单，以

onMouseOver 的 method 然後配合事件发生时去呼叫函数 hello() 就行了，不再

多加解释了，作法如下：

<html>

<head>

<script language="LiveScript">

<!-- Hiding

     function hello() {

       alert("哈罗!");

     }

</script>

</head>

<body>

<a href="" onMouseOver="hello()">link</a>

</body>

</html>

范例 6：

接下来我们要告诉你一个使用日期和时间的例子。在第一部分中，你已看过了

lastModified 的用法和作法。现在要告诉你的并非是印出网路上伺服器或文件

修改日期，而是你个人客户端机器的日期和时间。以下就是执行结果：

现在时间是： 15:32
今天日期为： 10/11/98

做法如下：
在本例中，我们必需首先建立一个日期变数，这可以由 today= new Date()来完成。

如果没有特别指定时间与日期的话，浏览器将会采用本地客户端机器的时间，若将

它放入变数 today 中。这儿要注意的是：我们并没有宣告 today 这个变数的型态，

这和 Java 或其他的程式语言在用到变数之前必需先加以宣告的方式有相当大的不

同。在完成 today 的日期变数後，我们等於建立了一个具有本地时间与日期的物件

(object)。接著就可以使用 get... 的 method 以取得 today 这个物件的时间和日期。

请注意 getMonth 这个 method 所取得的月份范围是由 0~11，所以必须加 1 以代

表真正的 1 月至 12 月。看完以上的例子後，想想你可以使你的文件变得有点

智慧，例如：某个文件有时效限制的话，你可以利用我们在上一部份的范例 4

中所提到的功能和这一个范例中所学习到的功能，设计一个让你的文件在 第10天

以後读到的话就会告诉读者："喂！这篇已过时了！"的程式，试试看，并不难！

除以上功能外，在建立日期物件时你也可以事先设定日期如下：

docStarted= new Date(96,0,13)

首先是年（西元），接著是月（但记得减 1），再接著是日。同样的方法也可以

加上时间的设定，如下：

docStarted = new Date(96,0,13,10,50,0)

前三个是日期的年、月、日，接著是时、分、秒。最後，我们必须提醒你，

JavaScript 并没有实际的日期型态，但是它却能毫不费力地显示出日期和时间，

原因是它是从 1 / 1 / 1970 0：0h 开始以 ms(milli seconds) 来计算目前的时间的，

这听起来似乎有些复杂，但你倒不用担心，它有标准的共用函数可以 计算，

你只要知道如何用就可以了！

范例 7：

接下来我们要为你介绍一个可以产生乱数的函数，也是以 JavaScript 所写的。

这个函数只是利用了一点小技巧而已，而这种技巧在大部分的编译器(compiler)中，

大都是如此（或类似）计算出乱数来的。我相信 JavaScript 最後应也会以相似的方

法来产生这样的 method ，如果它会提供这样功能的话。以下是此函数的结果：

这是一个计算产生的乱数： .17577887797942549

以下是这个作法的写法：

我们的做法是以上一个范例中的时间函数；它会出现一个很大的数，

利用这个数再加以运算即可！例如：将它拿来做正弦函数（sin）的运

算，得到的数再做绝对值的运算，结果可以得到一个介於 0 与 1 间的

实数。因为时间的改变是 ms 为单位，而且你绝不会获得相同的数字。

不过这个做法并不适合拿来快速的连续产生一系列的乱数，但如果你

是不定时，久久的用一次，那效果就不错了！

范例 8：

JavaScript 的一个重要特点是它可以制作视窗。你可以产生一个的视窗，并且

在此视窗中载入 HTML 文件，完全以 JavaScript 来航游网际网路（Internet ）。

接下来的范例就是告诉你如何开启一个视窗并且写点东西进去，你可先试试

按一下范中之接 钮看看！

原始程式如下：
这儿你又看到用按钮来启动函数。这次的函数 WinOpen()是藉著一个 open

的 method 来产生一个新的视窗。第一对双引号("")是用来描述欲载入至视窗

中的文件 URL 位置。如果留者空白的话，那就会呈现一个空白视窗，并可以

透过 JavaScript 写入东西！下一对双引号内的内容是这个新开启视窗的名字，

你可以喜欢给它任意一个名字，但不可加入空白，如用 Display Window 的话便

会出现错误讯息，请注意。接下来的一连串双引号内所 指定的是该视窗

的相关性质(properties)，这些蛮有趣的，你可以指定要不要有工具棒(toolbar) 、

卷轴(scrollbar)，等等，例如：如果你写 toolbar = yes，那就会在你所产生出

来的视窗中出现一排工具列。以下有许多你可以改变的视窗特性，请注意它们

字中间不可以有空白：

toolbar
location
directories
status
menubar
scrollbars
resizable
copyhistory
width=pixels
height=pixels

以上的 pixels 部分，你可以填入点数的数值，这数值是告诉浏览器这个视窗的

大小。在开启视窗，并且将它称为 msg 以後，就可以开始写些东西到视窗中了。

你可以写入一般正规的 HTML 语法文字。哇！这可不得了了，也就是说，你可以

利用先前使用者在 form 表格中输入给你的文章直接将它回应至浏览器上来了！这些

功能在几个月前大概还只能用 CGI 才能达到喔！现在你不用 CGI 也可以做了！

回主目录

希望你能对我的介绍感到还算不错。由於 JavaScript 尚未完全发展完成，

并且很可能会再继续地做一些更动，希望这儿的范例到时都还能执行，在

JavaScript 更多特性完成後，我也会继续地再为你介绍一些新的范例的！


Introduction to JavaScript - Part3

JavaScript简介
第三章

曾有许多网友问我有关JavaScript与框架(为求方便，以下均用frame表示)合用的问题。事实上， 若您同时想用frames和JavaScript的功能，首先您必需拥有Netscape Navigator 2.0 (或以上)浏览器( 至少目前是如此)。当然也有某些浏览器支援frames的功能--如:Oracle开发的PowerBrowser，但此 浏览器还只是Beta版，目前尚不支援JavaScript。

首先，我稍微解释一下frames的功用。因为frames功能才开发不久，仍有许多HTML文件中未使 用这项新功能。Frames最主要功用是"分割"您的视窗，使每个"小视窗"(frame)能显示不同的HTM L文件(译按:这有点类似电视的子母画面)。更妙的是，不同frame之间可以互动(interact)，也就是 说不同frame之间可以交换讯息与资料(information)。例如:假设您开了两个frames，第一个frame可 显示普通HTML文件，第二个frame可显示工具列(toolbar)。此工具列中可包含浏览您homepage所 需的各种按钮。如此一来，即使第一个frame载入了另一个HTML文件，您仍可在第二个frame中 看到工具列。

现在我先将上述特性展示给您瞧瞧。请按一下下面的按钮，看一看frames的长相。(如果您是线 上观看此文件，您可能需稍候一下才看得到结果，因为scripts必需由server中载入到您的机器)。

以下是此frame的写法:

<HTML>

<HEAD>

<title>Frames</title>

</HEAD>

    <FRAMESET ROWS="50%,50%">

    <FRAME SRC="frtest1.html" name="fr1">

    <FRAME SRC="frtest2.html" name="fr2">

  </FRAMESET>

</HTML>

首先您必须告诉浏览器您要开几个frame?这是由 <frameset...> 这个标签(tag)来宣告。rows这项 参数是告诉浏览器您想将视窗分割成几列?而 cols这项参数是告诉浏览器您想将视窗分割成几 行?您也可以用很多组的 <frameset...> tags 将视窗分割得更复杂。以下是 Netsacpe所提到的一个 范例:

<FRAMESET COLS="50%,50%">

  <FRAMESET ROWS="50%,50%">

    <FRAME SRC="cell.html">

    <FRAME SRC="cell.html">

  </FRAMESET>

  <FRAMESET ROWS="33%,33%,33%">

    <FRAME SRC="cell.html">

    <FRAME SRC="cell.html">

    <FRAME SRC="cell.html">

  </FRAMESET>

</FRAMESET>

上面这个例子产生了两行，而且第二行又分割成三列大小相等的空间。在第一个 <frameset> tag 中的 50%，50% 两项参数是用来表是frame的大小。
您可以给每个frame一个"名字" (name)。frame的名字在JavaScript语法中的地位非常重要。在本 章的第一个范例中您已学到如何替frame命名。接下来您可以用 <frame> tag 告诉浏览器您要载 入哪一个 HTML文件。

我想您已了解frames的基本用法，接下来我们再看一个有趣的范例:

上面的按钮将显示 : 按某个frame中的按钮後，会在另一frame中写入文字。
以下是此功能的原始码:

在产生frames效果之前，您需先制作下列原始码 (frames.html):

<HTML>

<HEAD>

<title>Frames</title>

</HEAD>

    <FRAMESET ROWS="50%,50%">

    <FRAME SRC="frame1.html" name="fr1" noresize>

    <FRAME SRC="frame2.html" name="fr2">

  </FRAMESET>

</HTML>

以下是 frame1.html 的原始码:

<HTML>

<HEAD>

<script language="JavaScript">

<!-- Hiding

     function hi() {

       document.write("嗨!<br>");

     }

     function yo() {

       document.write("呦!<br>");

     }

     function bla() {

       document.write("啦 啦 啦<br>");

     }

// -->

</script>

</HEAD>

<BODY>

这是第一个 frame!

</BODY>

</HTML>

以下是 frame2.html 的原始码:

<HTML>

<body>

这是第二个 frame!

<p>

<FORM NAME="buttonbar">

     <INPUT TYPE="button" VALUE="嗨" onClick="parent.fr1.hi()">

     <INPUT TYPE="button" VALUE="呦" onClick="parent.fr1.yo()">

     <INPUT TYPE="button" VALUE="啦" onCLick="parent.fr1.bla()">

</FORM>

</BODY>

</HTML>

哇!这些语法越来越长了!上述的语法是如何运作的呢?当使用者载入第一个档案 (frames.html)後 ，将会产生两个frame，并且在第一个frame(命名为 'fr1')中载入frame1.html，而在第二个frame ( 命名为 'fr2')中载入frame2.html。到目前为止都只是普通的 HTML 语法。或许您已发现在 frame1.html中包含了JavaScript语法，但此JavaScript并没有马上被执行。难到这些函式(functions) 是不必要的?亦或是我懒得删除这些不必要的函式?虽然我是懒散惯的人，但这些函式确实是必 须的。它们是被位於frame2.html中之JavaScript语法所呼叫而执行的。我在frame2.html中利用Java Script语法制作了三个按钮，制作按钮来呼叫函式的方法我已在第一章提过，相信您对onClick的 用法已相当熟悉。但是...... parent.fr1 是干嘛用的?

若您对物件观念已相当了解，相信它对您不是甚麽新鲜事。您可以看到frames.html同时呼叫 frame1.html 与 frame2.html两个档案，所以frames.html称为frame1.html与frame2.html的 parent (请 恕我直接用英文)。同理，这两个新的frame就称为frames.html的 child- frames。您可将这种复杂 的关系想像成阶层式架构(hierarchy)。以下我借助一个小 '图' 来厘清这种关系:

              frames.html                parent

               /      \

              /        \

             /          \

  fr1(frame1.html)     fr2(frame2.html)   children

当然您可依此类推，产生一些 'grandchildren' frames。 (当然，这并不是正式的名称):

              frames.html                parent

               /      \

              /        \

             /          \

  fr1(frame1.html)     fr2(frame2.html)   children

          /  \

         /    \

        /      \

    gchild1  gchild2                    'grandchildren'

若您想由frame2.html呼叫parent- frame中的任何函数，您只要将 parent 放在您欲呼叫函数名称之 前即可。同理，若由parent- frame呼叫位於frame1.html中的函数，您只需将 fr1 放在被呼叫函数 名称之前。为什麽用 fr1 呢?原因是我们在frames.html中开了两个frame，而且将它们分别命名为 fr1和 fr2。所以我用 fr1 代表第一个frame (frame1.html)。接下来的步骤就相当容易了。当我们欲 由frame2.html ( 命名为 fr2)呼叫第一个frame中的函式时该怎麽做?由上面的"小图"您可以发现， frame1.html 和frame2.html之间并无直接关连 (connection)，因此您不可以"直接"由frame2.html呼 叫位於 frame1.html中的函式。您必须透过parent- frame来呼叫它，所以正确指标(index)应为 parent.fr1。例如若您想由frame2.html呼叫 hi()，您必须写成 parent.fr1.hi()。这也就是为什麽 frame2.html中的 onClick要写成那种样子的原因了。

对了!附带提一点小东西。您或许已发现本章中都用<script language="JavaScript">代替前两章用 的<script language="LiveScript">。其实此二者间并没什麽差别。但起初JavaScript被植入Netscape 浏览器时，您只能用LiveScript语法。(这是一种由Netscape发展的旧语法，和JavaScript极为类似 )。我想既然我们讨论的是JavaScript函式，就应使用JavaScript语法。 (这只是我的一己之见，在 'JavaScript- society'中有许多关於LiveScript的讨论，目前也是众说纷纭....)

在此我要花一点时间讨论一个很多人关心的问题。当您观赏一个拥有数个frame的网页时，若您 想link至internet其它网页，这些frame并不会消失而且会带来视觉上的干扰。这些讨厌的frame应 该如何消除呢?

您只要在您的<a href...> tag中加入TARGET="_top" 就可解决这个困扰。方法如下:

<a href="goaway.html" TARGET="_top">如果您不想观赏我的网页了</a>

当然，您必须在您想要获得此效果的link中都加入TARGET="_top" 。若想要整个网页中的link 都有此效果，您可在此网页的head中加入<base target="_top">较方便。如此一来每个link被按下 後都可将frame消除。

返回主页 -


Introduction to JavaScript - Part4

JavaScript简介
第四章

这章我将告诉您如何在状态列 (statusbar) (也就是您浏览器最下方显示 URLs 的那一行) 显示文 字，并且将教您 '跑马灯' (以下简称 scroller ) 的工作原理。虽然以 JavaScript 完成的 scroller 目前 仍有些问题 (稍後会提到问题在哪儿?)，但我还是告诉您它是如何写成的。

首先，如何将文字填入 statusbar 呢?下述语法将告诉您如何做到这项功能: (按下按钮後请注视 statusbar 的变化)

很新奇吧! 请看看原始码 :

<html>

<head>

<script language="JavaScript">

<!-- Hide

function statbar(txt) {

   window.status = txt;

}

// -->

</script>

</head>

<body>

<form>

<input type="button" name="look" value="写入文字" onclick="statbar('嗨 ! 这就是状态
列 (statusbar) !');">

<input type="button" name="erase" value="清除文字" onclick="statbar('');">

</form>

</body>

</html>

我制作了两个都会呼叫 statbar(txt) 函式 (function) 的按钮。当此函式被呼叫後，字串经由括弧中 的变数 txt 传给 statbar(txt)。 (不一定要用 txt，用别的变数名也可以)。当电脑执行到 <form> tag 时， 一旦按下按钮就会呼叫 statbar(txt)。但是电脑并没有马上将 txt 的内容写在 statusbar，只是 将欲显示的字串存入 txt。换句话说，藉由呼叫函式，只是让变数 txt 得到一个值。因此当您按 下 '写入文字' 这个按钮後，会呼叫 statbar(txt) 而且 '嗨 ! 这就是状态列 (statusbar) !' 这个字串会 存入 txt 中。咻 ! 讲了这麽多只是想告诉您这种写法可预留一些弹性。什麽弹性呢?就是您可重 复使用 txt 这个变数。您看看第二个按钮，它也是呼叫相同的函式。若您不利用一个变数来传递 字串的话，就必须写两个不同的函式了。

那麽 statbar(txt) 到底做了些什麽?其实没什麽，只是将 txt 的内容写入变数 window.status中。这 是由 window.status = txt; 做的。另外若想消除文字，只需送一个空字串 ('') 给 statusbar。请注 意，因为在 onClick 中我们已经使用双引号 " ，所以这里必须用单引号 ' 。这是为了让浏览器辨 认哪两个引号是一对的，因此您必需双引号和单引号交替使用。

由此份简介文件第二章您已学过 onMouseOver 的特性了 :
<a href="tpage.html" onMouseOver="window.status='Just another stupid link...'; return true">
您可能会对一件事感到厌烦。那就是当 mouse 的指标已从 link 移开了，但是 statusbar 中的文字 还留在那 !没关系，我教您一个解决的办法。利用上面教您如何消除 statusbar 中文字的方法， 我们来写一个小函式。但是如何侦测出 mouse 的指标已从 link 移开并进而呼叫消除文字的函式 呢?侦测 mouse指标是否已从 link 移出的功能目前还无法达到，但可用 "计时器" 来暂时解决此 问题。

试试将 mouse 移到此 link 上看看 statusbar 的变化，但请不要按它。

怎麽样?很棒吧!看看下面的原始码您就知到这东西很简单。

<html>

<head>

<script language="JavaScript">

<!-- Hide

function moveover(txt) {

   window.status = txt;

   setTimeout("erase()",1000);

}

function erase() {

   window.status="";

}

// -->

</script>

</head>

<body>

<a href="dontclck.html" onMouseOver="moveover('瞬间即逝 !');return true;">

link</a>

</body>

</html>

这 script 的许多部份相信您已了解。 moveover(txt) 其实和先前的 statbar(txt) 差不多。erase()也和 先前所讨论的相同。在 HTML 网页中的 <body> tag 里我们加入一个具有 onMouseOver 功能之 link。当 mouse 指标移至 "link" 上就会呼叫 moveover(txt)，并且利用 txt 变数传递字串 '瞬间即逝 !'。接下来的步骤就和 statbar(txt) 一样， window.status 收到 txt 的值後将之显示在 statusbar 上。 而 setTimeout(...)这项新函式是用来作为一个 "定时器"。setTimeout(...)能作些什麽事呢?它的主 要特性是当某段设定的时间 "跑" 完了之後，便执行某函式。在这个例子中，於 1000 毫秒後 (也 就是 1 秒後) 就会执行 erase()。换句话说，当 1 秒结束後 moveover(txt) 的功能就会因 erase()的 自动执行而停止。
虽然规定时间 "跑" 完後定时器并不会重新启动，但您可以在 erase() 中再用一次setTimeout(...) ，使其循还不断，看起来就像一个跑马灯 (scroller)。

您已学到了 setTimeout 的功能和如何在 statusbar 中显示文字，接下我将教您如何制作一个在 statusbar 显示的 "跑马灯" (scroller)。

请按下方的按钮看看我做的 scroller。由於 script 需由 server 载入到您的电脑中，因此这要花一 点时间，请耐心等一下。

以下是原始码 :

<html>

<head>

<script language="JavaScript">

<!-- Hide

var scrtxt="怎麽样 ! 很酷吧 ! 您也可以试试."+"Here goes your message the visitors
to your page will "+

"look at for hours in pure fascination...";

var lentxt=scrtxt.length;

var width=100;

var pos=1-width;

function scroll() {

  pos++;

  var scroller="";

  if (pos==lentxt) {

    pos=1-width;

  }

  if (pos<0) {

    for (var i=1; i<=Math.abs(pos); i++) {

      scroller=scroller+" ";}

    scroller=scroller+scrtxt.substring(0,width-i+1);

  }

  else {

    scroller=scroller+scrtxt.substring(pos,width+pos);

  }

  window.status = scroller;

  setTimeout("scroll()",150);

  }

//-->

</script>

</head>

<body onLoad="scroll();return true;">
这里可显示您的网页 !
</body>

</html>

上面 script 用的语法相信大部份您已经懂了。 setTimeout(...) "告诉" 计时器当时间到了就呼叫 scroll()。 如此一来 scroller便会向前移动一步。在 script 的开头有许多计算式，那是用来决定文 字开始显示的位置，了不了解并不重要。一旦决定了文字的启始位置，就必需加些空格 (space) 以使文字能显示在正确位置。

在此章一开始我曾提到，此种 scroller 并不是很受欢迎。即使是，也不会持续很久。为什麽呢? 下面我列出几个主要原因:
当第一次看到 scroller 或许您会觉得很新奇，但久而久之便会觉得索然无味。当然，这是所有 "酷玩意儿" (cool trick) 皆有的现象。
其实这还不是主要原因，更严重的问题还在後头呢 ! 当您移动 mouse 时，您可以发现 scroller 的 速度改变了 (至少在我的机器上是如此)。尤其当您更改 setTimeout 的值为使 scroller 跑快一点时 ，这种情况更严重。不过这问题或许还有解决方法。更糟的是若让 scroller 跑久一点，会出现 Out of memory error的问题 ! 天呀 ! 这是 Netscape Navigator 2.0 的一个 "臭虫" (bug)。我们期待 新的版本能更正此 bug (译按 : Netscape Navigator Atlas Preview Release 已更正此 bug)。

在网路上有许多这方面的应用，您可以试著找找。我曾经看过有人将 scroller 放在 Homepage 中， 这应该不会太难。(译按 : 有兴趣的人可参考目录中本人所制做的 scroller)

返回主页 -


Introduction to JavaScript - Part5

JavaScript简介
第五章

阵列(arrays)的运用是程式设计中一项种要的技术。每一种程式语言均以某种特定方式来表示阵 列。或许您已了解阵列在程式设计中的好处，但翻遍Netscape所提供的文件，并没有提及如何使 用阵列。这是因为JavaScript并不支援阵列。但是现在我将教您如何在JavaScript中使用阵列。

首先，阵列是干啥用的?您可以把它看成一长串的变数(variables)。假设您现在需要宣告10个变数 ，您可以一个个将10个变数宣告为 a, b, c ...，但当您需要100个或更多的变数时，这种方法将会 变得很麻烦。若您使用一个拥有10个元素(elements)的阵列(暂且命名为 'MyArray')来表示这10个 变数，则可以用 MyArray[1]， MyArray[2]， MyArray[3]...分别代表第一,二,三....个变数(很多程 式语言是从0开始当作第一个元素，但在JavaScript语法中是从1开始)。因此若您想将第一个元素 (或称变数)的值指定为17，您只要写成 MyArray[1]=17即可。由此可看出阵列的功用和一般变 数是相同的。不光如此，若您想将所有元素的值均指定为17，您只要写一个简单的回圈(loop)即 可:
for (var i=1;i<11;i++) MyArray[i]=17
for- 这个指令是告诉电脑其後的指令总共要执行几次。for- 回圈是从1开使，也就是电脑会先执 行MyArray[1]=17。然後 i 会增加1并接著执行MyArray[2]=17。 i 每次递增1直到 i=10为止。

接下来教您如何做阵列的初始化(initialization)。这个问题曾在 JavaScript Mailing list中讨论过。 (如果您想订阅 mailing list， 您只要在e-mail中填入 subscribe javascript-digest 并寄到 majordomo @obscure.org 即可。接著您每天就会收到一到二个约20-30kB的大档案，这些档案包括所有来自 JavaScript- list的信件)。

function initArray() {

      this.length = initArray.arguments.length

      for (var i = 0; i < this.length; i++)

      this[i+1] = initArray.arguments[i]

   }
您不需要了解这个函式(function)的意义，您只要知道怎麽用就好。如果您要宣告一个拥有三个元 素的阵列，且其值分别指定为 17,18,19，您只要写成 : var MyArray= new initArray(17,18,19)。您 也可以用字串(strings)当作元素的值 : var heyho= new initArray("This","is","酷")。因此您不必管元 素值的型式(type)，即使混著用也行 : var Mixedup= new initArray(17,"yo",103)。

下面我将对一个阵列 'Mixedup' 作初始化，并显示阵列的内容 :

Element No. 1: 17
Element No. 2: yo
Element No. 3: 103

其原始码如下:

当我昨天写一个小游戏时，我遇到一个您也可能会碰到的问题。当您想清除视窗或frame中的内 容时，Netscape文件中提到了一个函式可用-- 'document.clear()'。但当您将此函式写入网页中， 它并不会如预期的清除视窗或frame中的内容。而且 document.clear()在各种平台(platform)上似乎 都无效。Gordon McComb告诉我一个清除视窗或frame中内容的好方法，您可以试试 :

     document.close();

     document.open();

     document.write("
");

您不一定要写最後一行 document.write("

");，只有当您想在视窗中写入某些东西时才需要加 入此行。上述方法对frame亦有效。

接下来我们谈一个可以让您在不同文件之间穿梭的语法-- back() 和 forward() 两个函式。通常 我们在网页中加的 back- link和 Netscape- Navigator中的 "Back键" 功能上并不相同。Netscape- Navigator中的 "Back键" 是回到您history list中的上一页。您现在也可利用JavaScript做到相同的 功能。只要按下此 link ，您可以再度回到此页。JavaScript语法的原始码 如下 :
您也可以用 history.go(-1) 和 history.go(1) 代替.

回主页 -


JavaScript 第 六 集

第 六 集

许 多 网 友 问 我 一 个 有 趣 的 问 题 : 如 何 用 mouse 按 一 下 便 可 同 时 载 入 两 页 文 件。 基 本 上 有 三 种 方 法 可 以 达 到 这 种 功 能。 第 一 种 方 法 是 制 作 一 个 按 钮， 让 使 用 者 按 下 後 去 启 动 一 个 能 同 时 将 两 份 文 件 载 入 不 同frames或 新 视 窗 的 函 式 (function)。 若 您 曾 经 看 过 此 份 简 介 文 件 的 其 它 章 节 的 话， 我 相 信 您 可 以 很 轻 易 写 出 这 种 语 法:

我 们 制 作 了 三 个 frame ， 第 一 个 frame 中 包 含 了 一 个 按 钮。 请 注 意， 第 一 个 HTML 档 案 只 是 用 来 打 开 frame 和 给 予 每 个 frame 一 个 名 字。 若 您 还 不 清 楚 JavaScript 和 frame 的 关 系， 可 以 先 阅 读 第 三 章。 不 过 在 此 还 是 照 例 让 您 瞧 瞧 原 始 码 (不 知 您 是 否 在 很 多 电 脑 书 籍 中 遇 到 一 个 相 同 的 困 扰， 那 就 是 作 者 常 把 一 些 自 认 很 简 单 的 东 西 忽 略 不 提， 结 果 那 些 东 西 正 是 读 者 搞 不 懂 的 地 方 ! 所 以， 若 您 对 我 提 的 东 西 已 很 了 解， 请 发 挥 一 下 您 的 耐 性 :-)

frames2.html

<HTML>
<HEAD>
<title>Frames</title>
</HEAD>
    <FRAMESET COLS="295,*">
  <FRAMESET ROWS="100%,*">
    <FRAME SRC="loadtwo.html" NAME="fr1">
      </FRAMESET>
  <FRAMESET ROWS="75%,25%">
    <FRAME SRC="cell.html" NAME="fr2">
    <FRAME SRC="cell.html" NAME="fr3">
      </FRAMESET>
</FRAMESET>
</HTML>
第 一 个 frame 会 载 入 loadtwo.html 并 产 生 一 个 按 钮 :

loadtwo.html

<HTML>
<HEAD>
<script language="JavaScript">
<!-- Hiding
  function loadtwo(page2, page3) {
     parent.fr2.location.href=page2;
     parent.fr3.location.href=page3;
}
// -->
</script>
</HEAD>
<BODY>
<FORM NAME="buttons">
     <INPUT TYPE="button" VALUE="同 时 载 入 两 份 文 件" onClick="loadtwo('frtest1.html',
     'frtest2.html')">
</FORM>
</BODY>
</HTML>

按 下 按 钮 後， 电 脑 会 传 递 两 个 字 串 给 loadtwo() 并 将 之 启 动。 由 loadtwo() 中 可 以 看 出， 第 一 个 字 串 是 用 来 定 义 第 二 个 frame fr2所 载 入 文 件 的 位 址 和 档 案 名。 若 您 想 定 义 另 外 的 按 钮 来 载 入 不 同 的 文 件， 您 可 以 重 复 使 用 此 函 式。 只 要 将 文 件 的 URLs (addresses) 传 给 loadtwo()即 可。

接 下 来 谈 谈 用 hyperlinks 同 时 载 入 两 页 文 件 的 第 二 种 方 法。 在 Internet 上 您 可 以 发 现 许 多 网 页 使 用 <a href="yourlink.html" onCLick="yourfunction()">来 达 到 上 述 提 及 的 功 能。 但 此 语 法 并 不 能 在 所 有 平 台 上 均 正 常 执 行， 因 此 最 好 不 要 用 此 语 法。 现 在 我 告 诉 您 另 一 种 写 法 : 我 们 可 改 用 下 述 JavaScript 语 法:

<a href="javascript:myfunction()">My Link</a>
此 种 方 式 非 常 简 单 而 且 在 所 有 浏 览 器 中 均 能 正 常 执 行。 您 只 要 写 上 javascript: 并 加 上 您 想 联 结 的 函 式 名 即 可。 若 此 函 式 名 称 设 为 'loadtwo()' ， 那 您 就 可 藉 由 按 下 此 hyperlink 来 达 到 同 时 载 入 两 份 文 件 的 目 的 了。

再 接 着 谈 谈 用 mouse 按 一 下 便 可 同 时 载 入 两 页 文 件 的 第 三 种 方 法， 此 方 法 可 以 以 hyperlinks 或 按 钮 来 执 行。 您 可 先 在 第 二 个frame 中 载 入 一 个 HTML 文 件 :
<a href="getfr2.html" target="fr2">请 按 这 里 !</a>
然 後 在 此 文 件 中 (getfr2.html) 加 入 onLoad 这 项 指 令， 用 来 触 发 第 三 个 frame 载 入 另 一 份 文 件。 如 此 一 来 便 可 同 时 载 入 两 份 文 件。getfr2.html 档 的 原 始 码 如 下 :

<HTML>
<BODY onLoad="parent.fr3.location.href='getfr3.html'; return true;">
文 件 内 容.....。
</body>
</html>

当 然， 您 必 须 在 所 有 会 被 载 入 到 第 二 个 frame 的 文 件 中 加 入 onLoad 这 项 指 令。

另 一 个 常 遇 见 的 问 题 是 如 何 开 一 个 新 视 窗 并 载 入 文 件?我 们 想 达 到 的 效 果 是 当 使 用 者 按 一 下 mouse 便 会 '弹' 出 一 个 新 视 窗。 很 简 单， 只 要 在 <a href...> 中 利 用 target 这 项 特 性 就 可 达 到 此 效 果。 例 如 :
<a href="goanywhere.html" target="Resource Window">Go!</a>

现 在 我 将 谈 谈 在 JavaScript 中 几 种 常 用 的 运 算 子 (operator)。 运 算 子 可 以 使 您 的 JavaScript 语 法 更 精 简。 假 设 您 想 测 试 变 数 x 是 否 大 於 3 且 小 於 10， 您 可 写 成 :

if (x>3)
  if (x<10)
    doanything();

当 满 足 x>3 且 x<10 时， 就 会 执 行 doanything()。 还 有 一 种 更 精 简 的 写 法 :

if (x>3 && x<10) doanything();
' &&' 称 为 AND- 运 算 子。 还 有 另 一 种 被 称 为 OR- 运 算 子 的 东 东 可 让 您 用 来 检 视 是 否 变 数 x 等 於 5 或 变 数 y 等 於 17 :

if (x==5 || y==17) doanything();
当 满 足 x==3 或 y==17 时， 就 会 执 行 doanything()。 当 然， 当 两 者 皆 成 立 时 也 会 执 行 doanything()。
在 JavaScript 中 是 利 用 == 来 做 比 较 的 工 作 (其 它 尚 有 <，>，<= 和 >=)， 这 些 都 和 C/C++ 的 语 法 相 同。 另 外 单 一 '=' 是 用 来 将 数 值 存 入 变 数 用 的。 (在 Pascal 语 法 中 将 数 值 指 定 给 变 数 是 用 :=， 而 做 比 较 是 用 单 一 的 '='， 这 和 JavaScript 语 法 有 点 不 同)

若 您 想 利 用 '不 等 於' 这 项 特 性， 您 可 以 用 !=。 例 如 : x != 17.

尚 有 许 多 可 以 精 简 您 的 JavaScript 语 法 的 运 算 子， 去 翻 翻 Netscape 的 文 件 吧 !

回 主 目 录


JavaScript 第 七 集

第 七 集

输 入 表 单 (form) 对 某 些 Internet 上 的 网 页 而 言 是 很 重 要 的。 通 常 form 的 输 入 内 容 会 被 送 回 server 中 做 处 理。 JavaScript 具 有 确 认 输 入 值 的 功 能， 可 以 事 先 确 保 这 些 值 是 属 於 "合 法 的"， 进 而 避 免 将 错 误 的 输 入 值 送 回 server。 首 先 我 将 告 诉 您 如 何 对 form 的 输 入 做 确 认 的 工 作， 再 来 我 将 会 提 到 用 JavaScript 将 资 料 送 回 server 的 可 能 性。

咱 们 开 始 吧 ! 我 先 写 一 个 简 单 的 语 法。 在 下 面 我 加 了 两 个 text- 元 件 (element)， 请 将 您 的 大 名 写 入 第 一 个 空 格， 并 将 您 的 e-mail address 写 入 第 二 个 空 格。 您 可 在 这 两 个 空 格 中 任 意 输 入 并 按 下 按 钮。 您 也 可 以 不 输 入 任 何 东 西 就 按 下 按 钮 试 试 !

请 输 入 您 的 大 名 :

请 输 入 您 的 e-mail address :

对 第 一 个 空 格 而 言， 若 您 没 有 键 入 任 何 东 西， 电 脑 便 会 出 现 一 个 错 误 讯 息， 并 请 您 再 输 入 一 次。 当 然， 此 空 格 会 把 任 何 输 入 的 字 串 都 视 为 "合 法 的" 输 入， 它 无 法 辨 认 出 您 输 入 的 名 字 是 正 确 的 或 是 胡 　 的。 即 始 您 输 入 的 是 数 字， 它 也 会 把 此 数 字 当 成 您 的 大 名。 例 如 您 输 入 '17'， 它 将 会 显 示 '嗨 ! 17'。
第 二 个 空 格 就 设 计 得 稍 微 复 杂 一 点 了。 您 可 试 着 输 入 一 个 简 单 的 字 串 - 例 如 您 的 大 名， 它 将 会 显 示 错 误 讯 息， 并 请 您 再 输 入 一 次 (除 非 您 输 入 的 字 串 含 有 @ ...)。 这 个 空 格 的 确 认 标 准 是 检 视 您 输 入 的 字 串 中 是 否 含 有 @ 。 即 使 只 输 入 一 个 @， 它 也 会 被 视 为 合 法 的 输 入 --- 虽 然 这 也 不 是 正 确 的 e-mail address。 所 有 Internet 的 e-mail address 皆 含 有 @ ， 因 此 对 e-mail address 输 入 值 做 此 种 确 认 工 作 是 很 适 合 的。

接 下 来 看 看 上 述 功 能 的 原 始 码 吧 :

<html>
<head>
<script language="JavaScript">
<!-- Hide

function test1(form) {
  if (form.text1.value == "")
    alert("您 没 写 上 任 何 东 西， 请 再 输 入 一 次 !")
  else {
   alert("嗨 "+form.text1.value+"! 您 已 输 入 完 成 !");
  }
}

function test2(form) {
  if (form.text2.value == "" ||
      form.text2.value.indexOf('@', 0) == -1)
        alert("这 不 是 正 确 的 e-mail address! 请 再 输 入 一 次 !");
  else alert("您 已 输 入 完 成 !");
}
// -->
</script>
</head>

<body>
<form name="first">
Enter your name:<br>
<input type="text" name="text1">
<input type="button" name="button1" value="输 入 测 试" onClick="test1(this.form)">
<P>
Enter your e-mail address:<br>
<input type="text" name="text2">
<input type="button" name="button2" value="输 入 测 试" onClick="test2(this.form)">
</body>

先 看 看 body- 之 後 的 HTML 语 法。 我 们 嵌 入 了 两 个 text 元 件 和 两 个 按 钮。 第 一 个 按 钮 呼 叫 test1(...)， 第 二 个 按 钮 呼 叫 test2(...)。 this.form这 个 变 数 会 将 此 form 的 名 字 (在 此 例 中 就 是 first) 传 给 函 式 (function)， 以 便 能 正 确 将 元 件 "定 址" (address)。
test1(form) 的 功 用 在 於 检 查 您 是 否 输 入 字 串 (亦 即 检 查 是 否 为 "空 字 串") ? 此 项 工 作 是 由 if(form.text1.value == "")... 所 执 行。 'form' 这 个 变 数 将 会 接 收 由 'this.form' 所 传 来 的 值。 但 我 们 如 何 在 test1(...) 中 抓 取 我 们 所 输 入 的 字 串 呢?您 可 利 用 'value' 这 个 变 数 再 加 上 'form.text1' 来 抓 所 输 入 的 字 串。 然 後 将 它 和 " " 比 较， 检 查 是 否 为 "空 字 串"。 若 是 "空 字 串" 则 表 示 并 无 输 入 任 何 东 西， 那 麽 Netscape 将 会 出 现 警 告 并 要 求 您 再 输 入 一 次。 若 test1(...) 检 查 结 果 并 非 "空 字 串"， 则 会 出 现 "您 已 输 入 完 成 !" 的 讯 息。 请 注 意， 即 使 只 输 入 一 个 空 白 (space)， test1(...)也 会 将 之 视 为 合 法 输 入。 当 然， 您 也 可 以 略 施 小 技 来 排 除 上 述 可 能 性， 我 相 信 这 很 容 易。
现 在 请 看 test2(form)。 在 此 函 式 中 我 们 利 用 相 同 的 方 法 来 检 测 输 入 值 是 否 为 空 字 串， 但 是 我 在 if- 指 令 中 加 入 了 额 外 的 检 测 功 能。 || 这 个 符 号 代 表 OR 运 算 子 (operator)， 您 可 在 第 六 章 中 学 习 它 的 用 法。
if- 指 令 用 来 检 测 第 一 与 第 二 个 比 较 式 是 否 其 中 之 一 为 "真"?若 有 其 中 之 一 为 "真"， 则 整 个 if- 指 令 即 为 "真"， 如 此 便 会 执 行 其 後 的 指 令。 换 句 话 说， 若 您 没 有 输 入 任 何 字 串 或 您 输 入 的 字 串 中 没 有 包 含 '@'， 均 会 被 视 为 "不 合 法" 输 入。

您 知 到 有 几 种 方 法 可 用 来 送 出 form 的 内 容 吗?最 简 单 的 方 法 就 是 利 用 e-mail 来 送 出 form 的 内 容。 我 下 面 介 绍 的 方 法 就 是 属 於 这 一 种。 若 您 不 想 利 用 e-mail 来 送 出 form 的 内 容 且 想 让 server 能 自 动 处 理 form 的 输 入 值， 此 时 此 刻 只 有 CGI 能 做 得 到。 譬 如 您 想 做 一 个 类 似 Yahoo 可 以 让 使 用 者 迅 速 得 到 结 果 的 搜 寻 引 擎 (search engine)， 您 就 必 须 使 用 CGI。 如 此 一 来 使 用 者 才 不 需 等 待 系 统 管 理 者 处 理 form 的 输 入 值， 而 可 由 server 自 动 处 理 并 迅 速 将 处 理 结 果 报 告 给 使 用 者。 目 前 JavaScript 无 法 达 到 此 种 功 能。 即 使 您 想 制 做 一 个 "访 客 签 名 簿" (guestbook)， 也 不 可 能 利 用 JavaScript 来 叫 server 自 动 将 资 料 加 入 网 页 中。 目 前 只 有 CGI 能 做 到 如 此。 但 您 可 以 制 做 一 个 利 用 e-mail 传 送 使 用 者 资 料 的 guestbook， 只 是 您 需 以 手 动 (manual) 方 式 来 处 理 使 用 者 所 传 来 的 资 料。 若 您 一 天 不 是 收 到 很 多 使 用 者 送 来 的 资 料 的 话， 这 也 未 尝 不 可。
以 下 语 法 只 使 用 到 普 通 的 HTML 语 法， 并 不 需 用 到 JavaScript ! 只 有 当 您 想 在 资 料 送 出 前 做 一 些 确 认 工 作 的 话， 才 需 用 到 JavaScript。 虽 然 目 前 有 些 浏 览 器 无 法 使 用 mailto- 这 项 指 令， 我 相 信 较 新 版 的 浏 览 器 都 会 支 援 这 个 指 令。

<FORM METHOD=POST ACTION="mailto:your_email@goes.here">
<H3>您 喜 欢 我 的 网 页 吗 ?</H3>
  <INPUT NAME="choice" TYPE="RADIO" VALUE="1">一 点 也 不 喜 欢。<BR>
  <INPUT NAME="choice" TYPE="RADIO" VALUE="2" CHECKED>简 直 浪 费 我 的 时 间。<BR>
  <INPUT NAME="choice" TYPE="RADIO" VALUE="3">这 简 直 是 Net 上 最 烂 的 站 台。<BR>
  <INPUT NAME="submit" TYPE="SUBMIT" VALUE="Send">
</FORM>
上 述 语 法 可 藉 由 e-mail 收 到 使 用 者 对 您 网 页 的 观 感。 唯 一 的 困 扰 是 您 可 能 会 收 到 内 容 类 似 密 语 (cryptic) 的 mail。 mail 内 容 的 空 格 (space) 有 时 会 以 '+' 代 替， 有 时 会 以 '%20' 代 替。 看+起+来+ 就+像+这+样。 我 相 信 网 路 上 应 有 某 种 程 式 可 将 收 到 的 mail 转 换 成 "可 读" 的 语 句。

另 外 有 一 种 不 错 的 应 用 可 使 您 的 表 单 输 入 更 具 "亲 和 性" (user-friendly)。 您 可 以 指 定 一 开 始 先"定 焦" (focus)於 哪 个 元 件 (element， 简 单 的 说 就 是 输 入 项)。 或 是 您 可 让 浏 览 器 "定 焦" 於 使 用 者 输 入 错 误 的 表 单。 换 句 话 说， 浏 览 器 将 会 把 mouse 的 游 标 放 在 您 "定 焦" 的 元 件 上， 如 此 一 来 使 用 者 便 不 需 在 输 入 字 串 之 前 按 一 下 mouse。 请 看 这 项 功 能 的 原 始 码 :

function setfocus() {
        document.first.text1.focus();
        return;
}

这 项 语 法 是 将 "定 焦" 放 在 第 一 个 text- 元 件 上 (以 本 章 为 例， 就 是 在 "请 输 入 您 的 大 名" 的 空 格 中 有 游 标 在 闪 烁)。 您 必 需 在 语 法 中 指 定 您 想 "定 焦" 的 表 单 名 字 (以 本 章 为 例， 就 是 first) 和 元 件 的 名 字 (以 本 章 为 例， 就 是 text1)。 若 您 在 一 开 始 载 入 网 页 时 就 想 "定 焦" 於 某 个 元 件 上， 只 要 在 <body>- tag 中 利 用 onLoad- 即 可 :

<body onLoad="setfocus()">

回 主 目 录


Javascript的保留字

以下的保留字不可以用作变量,函数名,对象名等,其中有的保留字是为以后JAVASCRIPT扩展用的.
  • abstract
  • boolean
  • break
  • byte
  • case
  • catch
  • char
  • class
  • const
  • continue
  • default
  • do
  • double
  • else
  • extends
  • false
  • final
  • finally
  • float
  • for
  • function
  • goto
  • if
  • implements
  • import
  • in
  • instanceof
  • int
  • interface
  • long
  • native
  • new
  • null
  • package
  • private
  • protected
  • public
  • return
  • short
  • static
  • super
  • switch
  • synchronized
  • this
  • throw
  • throws
  • transient
  • true
  • try
  • var
  • void
  • while
  • with
    • 回主目录


JavaScript的方法

以下的一些"方法"可用在JavaScript:
  • abs
  • acos
  • alert
  • anchor
  • asin
  • assign
  • atan
  • back
  • big
  • blink
  • blur
  • bold
  • ceil
  • charAt
  • clear
  • clearTimeout
  • click
  • close
  • confirm
  • cos
  • eval
  • exp
  • fixed
  • floor
  • focus
  • fontcolor
  • fontsize
  • forward
  • getDate
  • getDay
  • getHours
  • getMinutes
  • getMonth
  • getSeconds
  • getTime
  • getTimeZoneoffset
  • getYear
  • go
  • indexOf
  • italics
  • lastIndexOf
  • link
  • log
  • max
  • min
  • open
  • parse
  • pow
  • prompt
  • random
  • round
  • select
  • setDate
  • setHours
  • setMinutes
  • setMonth
  • setSeconds
  • setTimeout
  • setTime
  • setYear
  • sin
  • small
  • sqrt
  • strike
  • sub
  • submit
  • substring
  • sup
  • tan
  • toGMTString
  • toLocaleString
  • toLowerCase
  • toString
  • toUpperCase
  • UTC
  • write
  • writeln

    • abs method

    Returns the absolute value of its argument.

    Syntax

    abs(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    acos method

    Returns the arc cosine (in radians) of its argument.

    Syntax

    acos(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • asin, atan, cos, sin, tan methods

    alert method

    Displays an Alert dialog box with a message and an OK button.

    Syntax

    alert("message")

    The argument message is any string.

    Description

    Use the alert method to display a message that does not require a user decision. The message argument specifies a message that the dialog box contains.

    Applies to

    window

    Examples

    In the following example, the testValue function checks the name entered by a user in the text element of a form to make sure that it is no more than eight characters in length. This example uses the alert method to prompt the user of an application to enter a valid value.

    function testValue(textElement) {
   if (textElement.length > 8) {
      alert("Please enter a name that is 8 characters or less")
   }
}
    You can call the testValue function in the onBlur event handler of a form's text element, as shown in the following example:
    Name: <INPUT TYPE="text" NAME="userName" onBlur="testValue(userName)">

    See also

  • confirm, prompt methods

    anchor method

    Causes the calling string object to be a named anchor by surrounding it with HTML anchor tags, <A NAME=...> </A>.

    Syntax

    string.anchor(name)

    The argument name can be any string.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • link method

    asin method

    Returns the arc sine (in radians) of its argument.

    Syntax

    asin(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • acos, atan, cos, sin, tan methods

    assign method

    Sets location.href so you don't have to type ".href" complements toString().

    Syntax

    assign()

    Description

    Do not call the assign method. It exists so you can use 'location=...' instead of 'location.href=...'. xxx Description to be supplied.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    atan method

    Returns the arc tangent (in radians) of its argument.

    Syntax

    atan(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • acos, asin, cos, sin, tan methods

    back method

    Loads the previous URL in the history list.

    Syntax

    back()

    Description

    This method performs the same action as a user choosing the Back button in the Navigator. The back method is the same as go(-1).

    Applies to

    history

    Examples

    xxx Examples to be supplied.

    See also

  • forward, go methods

    big method

    Causes the calling string object to be displayed in big font by surrounding it with HTML big font tags, <BIG> and </BIG>.

    Syntax

    big()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • fontsize, small methods

    blink method

    Causes the calling string object to blink by surrounding it with HTML blink tags, <BLINK> ... </BLINK>.

    Syntax

    blink()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • bold, italics, strike methods

    blur method

    For password, text, and textArea, removes focus to the object.

    Syntax

    blur()

    Description

    Use the blur method to remove focus from a specific form element.

    Applies to

    password, text, textArea

    Examples

    xxx Examples to be supplied.

    See also

  • focus, select methods

    bold method

    Causes the calling string object to be displayed as bold by surrounding it with HTML bold tags, <B> ... </B>.

    Syntax

    bold()
    NOTE: For Beta4, use B() for this method.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • blink, italics, strike methods

    ceil method

    Returns the least integer greater than or equal to its argument.

    Syntax

    ceil(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • floor method

    charAt method

    Returns the character at the specified index.

    Syntax

    charAt(index)

    index is any integer from 0 to string.length() - 1.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • indexOf, lastIndexOf methods

    clear method

    Clears the window.

    Syntax

    clear()

    Description

    xxx Description to be supplied.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    clearTimeout method

    Cancels a timeout that was set with the setTimeout method.

    Syntax

    clearTimeout(timeoutID)

    timeoutID is a timeout setting that was returned by a previous call to the setTimeout method.

    Description

    xxx Description to be supplied. Applies to

    window

    Examples

    xxx Examples to be supplied.

    See also

  • setTimeout

    click method

    Simulates a mouse click on the calling form element.

    Syntax

    click()

    Description

    The effect of the click method varies according to the calling element:

  • For button, reset, and submit, xxx.
  • For a radioButton, selects a radio button.
  • For a checkbox, checks the check box and sets its value to on.
  • For a selection, sets its value.

    Applies to

    button, checkbox, radioButton, reset, selection, submit

    Examples

    xxx Examples to be supplied.

    close method

    For document and window, closes the window. xxx Not yet implemented in Beta 4.

    Syntax

    close()

    Description

    Document description to be supplied.

    The close method closes the current window.

    Applies to

    document, window

    Examples

    Any of the following examples close the current window:

    window.close()
self.close()
close()

    See also

  • open method

    confirm method

    Displays a Confirm dialog box with the specified message and OK and Cancel buttons.

    Syntax

    confirm("message")

    The argument message is any string.

    Description

    Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. The message argument specifies a message that prompts the user for the decison. The confirm method returns true if the user chooses OK and false if the user chooses Cancel.

    Applies to

    window

    Examples

    This example uses the confirm method in the confirmCleanUp function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp() function closes the application.

    function confirmCleanUp() {
   if (confirm("Are you sure you want to quit this application?")) {
      cleanUp()
   }
}
    You can call the confirmCleanUp function in the onClick event handler of a form's pushbutton, as shown in the following example:
    <INPUT TYPE="button" VALUE="Quit" onClick="confirmCleanUp()">

    See also

  • alert, prompt methods

    cos method

    Returns the cosine of its argument. The argument is in radians.

    Syntax

    cos(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • acos, asin, atan, sin, tan methods

    eval function

    The eval function is a function built-in to JavaScript. It is not a method associated with any object, but is part of the language itself.

    Syntax

    eval(expression)

    Description

    The eval function takes a JavaScript arthimetic expression as its argument and returns the value of the argument as a number.

    Example

    Both of the uses of eval in the following example assign the value 42 to the variable result.

    x = 6
result = eval((3+3)*7)
result = eval(x*7)

    exp method

    Returns e to the power of its argument, i.e. ex, where x is the argument, and e is Euler's constant, the base of the natural logarithms.

    Syntax

    exp(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • log method

    fixed method

    Causes the calling string object to be displayed in fixed-pitch font in HTML by surrounding it with typewriter text tags, <fixed> ... </fixed>.

    Syntax

    fixed()
    NOTE: For Beta4, use TT() for this method.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    floor method

    Returns the greatest integer less than or equal to its argument.

    Syntax

    floor(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • ceil method

    focus method

    For password, text, and textArea, gives focus to the object.

    Syntax

    focus()

    Description

    Use the focus method to navigate to a specific form element and give it focus. You can then either programatically enter a value in the element or let the user enter a value.

    Applies to

    password, text, textArea

    Examples

    In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the focus method returns focus to the password field and the select method highlights it so the user can re-enter the password.

    function checkPassword(userPass) {
   if (badPassword) {
      alert("Please enter your password again.")
      userPass.focus()
      userPass.select()
   }
}
    This example assumes that the password is defined as:
    <INPUT TYPE=password NAME=userPass>

    See also

  • blur, select methods

    fontcolor method

    Causes the calling string object to be displayed in the specified color by surrounding it with HTML font color tags, <FONTCOLOR=color> ... </FONTCOLOR>.

    Syntax

    fontcolor(color)

    The argument to the method, color, must be a string containing a hashmark (#) followed by a triplet of hexadecimal number pairs. These three pairs represent the red, green, and blue values for the desired color, respectively.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    fontsize method

    Causes the calling string object to be displayed in the specified font size by surrounding it with HTML font size tags, <FONTSIZE=size> ... </FONTSIZE>.

    Syntax

    fontsize(size)

    The argument to the method, size, must be an integer between one and seven.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • big, small methods

    forward method

    Loads the next URL in the history list.

    Syntax

    forward()

    Description

    This method performs the same action as a user choosing the Forward button in the Navigator. The forward method is the same as go(1).

    Applies to

    history

    Examples

    xxx Examples to be supplied.

    See also

  • back, go methods

    getDate method

    Syntax

    dateObj.getDate()

    where dateObj is a date object.

    Description

    Returns the day of the month for the date object, an integer between 1 and 31.

    Applies to

    Date

    Examples

    The second statement below assigns the value 25 to the variable day, based on the value of the date object Xmas95.

    Xmas95 = new Date("December 25, 1995 23:15:00")
day = Xmas95.getDate()

    See also

  • xxx To be supplied.

    getDay method

    Syntax

    dateObj.getDay()

    where dateObj is a date object.

    Description

    Returns the day of the week for the date object, an integer corresponding to the day of the week: zero for Sunday, one for Monday, two for Tuesday, and so on.

    Applies to

    Date

    Examples

    The second statement below assigns the value 1 to weekday, based on the value of the date object Xmas95. This is because December 25, 1995 is a Monday.

    Xmas95 = new Date("December 25, 1995 23:15:00")
weekday = Xmas95.getDay()

    See also

  • xxx To be supplied.

    getHours method

    Syntax

    dateObj.getHours()

    where dateObj is a date object.

    Description

    Returns the hour for the date object, an integer between 0 and 23.

    Applies to

    Date

    Examples

    The second statement below assigns the value 23 to the variable hours, based on the value of the date object Xmas95.

    Xmas95 = new Date("December 25, 1995 23:15:00")
hours = Xmas95.getHours()

    See also

  • xxx To be supplied.

    getMinutes method

    Syntax

    dateObjgetMinute()

    where dateObj is a date object.

    Description

    Returns the minutes in the date object, an integer between 0 and 59.

    Applies to

    Date

    Examples

    The second statement below assigns the value 15 to the variable minutes, based on the value of the date object Xmas95.

    Xmas95 = new Date("December 25, 1995 23:15:00")
minutes = Xmas95.getMinutes()

    See also

  • xxx To be supplied.

    getMonth method

    Syntax

    dateObj.getMonth()

    where dateObj is a date object.

    Description

    Returns the month in the date object, an integer between zero and eleven. Zero corresponds to January, one to Februrary, and so on.

    Applies to

    Date

    Examples

    The second statement below assigns the value 11 to the variable month, based on the value of the date object Xmas95.

    Xmas95 = new Date("December 25, 1995 23:15:00")
month = Xmas95.getDate()

    See also

  • xxx To be supplied.

    getSeconds method

    Syntax

    dateObj.getSeconds()

    where dateObj is a date object.

    Description

    Returns the seconds in the current time, an integer between 0 and 59.

    Applies to

    Date

    Examples

    The second statement below assigns the value 30 to the variable secs, based on the value of the date object Xmas95.

    Xmas95 = new Date("December 25, 1995 23:15:30")
secs = Xmas95.getSeconds()

    See also

  • xxx To be supplied.

    getTime method

    Syntax

    dateObj.getTime()

    where dateObj is a date object.

    Description

    Returns the numeric value for the date object. This number is the number of milliseconds since the epoch (1 January 1970 00:00:00) You can use this method to help assign a date and time to another date object.

    Applies to

    Date

    Examples

    The following example assigns the date value of theBigDay to sameAsBigDay.

    theBigDay = new Date("July 1, 1999")
sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime())

    See also

  • xxx To be supplied.

    getTimezoneOffset method

    Syntax

    dateObj.getTimezoneOffset()

    where dateObj is a date object.

    Description

    Return the time zone offset in minutes for the current locale, i.e. the difference between the local time and GMT. This value would be a constant except for daylight savings time.

    Applies to

    Date

    Examples

    x = new Date();
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60;

    See also

  • xxx To be supplied.

    getYear method

    Syntax

    getyear()

    Description

    Returns the year in the date object, less 1900.

    Applies to

    Date

    Examples

    The second statement below assigns the value 95 to the variable year, based on the value of the date object Xmas95.

    Xmas95 = new Date("December 25, 1995 23:15:00")
year = Xmas95.getYear()

    See also

  • xxx To be supplied.

    go method

    The argument delta is an integer. If delta is greater than zero, then it loads the URL that is that number of entries forward in the history list; otherwise, it loads the URL that is that number of entries backward in the history list.

    The argument string is a string. Go to the newest history entry whose title or URL contains string as a substring; substring matching is case-insensitive.

    Syntax

    go(delta | "string")

    Description

    xxx Description to be supplied.

    Applies to

    history

    Examples

    xxx Examples to be supplied.

    See also

  • back, forward methods

    indexOf method

    Returns the index within the calling string object of the first occurrence of the specified character, starting the search at fromIndex.

    Syntax

    indexOf(character, [fromIndex])

    character is the character to search for.
    fromIndex is the location within the calling string to start the search from, any integer from 0 to string.length() - 1.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • charAt, lastIndexOf methods

    italics method

    Causes the calling string object to be italicized by surrounding it with HTML italics tags, <I> ... </I>.

    Syntax

    italics()
    NOTE: For Beta4, use I() for this method.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • blink, bold, strike methods

    lastIndexOf method

    Returns the index within the calling string object of the last occurrence of the specified character. The calling string is searched backwards, starting at fromIndex.

    Syntax

    indexOf(character, [fromIndex])

    character is the character to search for.
    fromIndex is the location within the calling string to start the search from, any integer from 0 to string.length() - 1.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • charAt, indexOf methods

    link method

    Causes the calling string object to be a hyperlink by surrounding it with HTML hyperlink tags, <A HREF=...> </A>.

    Syntax

    link(location)
    The argument to the method, location, should be a valid URL.

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • anchor method

    log method

    Returns the natural logarithm (base e) of its argument.

    Syntax

    log(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • exp method

    max method

    Returns the greater of its two arguments.

    Syntax

    max(arg1, arg2)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • min method

    min method

    Returns the lesser of its two arguments.

    Syntax

    min(arg1, arg2)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • max method

    open method

    For the window object, opens a new web browser window. xxx For the document object, description to be supplied.

    Syntax

    The first form of the syntax is for the document object; the second form is for window.

    1. document.open("MIME type")
2. window.open("URL", "windowName", ["windowFeatures"])

    URL specifies the URL to open in the new window.
    windowName specifies a name for the window object being opened.
    windowFeatures is a comma-separated list of any of the following options and values:

       toolbar[=yes|no]|[=1|0]
   location[=yes|no]|[=1|0]
   directories[=yes|no]|[=1|0]
   status[=yes|no]|[=1|0]
   menubar[=yes|no]|[=1|0]
   scrollbars[=yes|no]|[=1|0]
   resizable[=yes|no]|[=1|0]
   copyhistory[=yes|no]|[=1|0]
   width=pixels
   height=pixels

    You may use any subset of these options. Separate options with a comma. Do not put spaces between the options.

    pixels is a positive integer specifying the dimension in pixels.

    NOTE: In event handlers, you must specify window.open() unless you want to call document.open() because of the scoping of static objects in JavaScript.

    Description for window

    The open method opens a new web browser window on the client, similar to choosing File|New Web Browser from the menu of the Navigator. The URL argument specifies the URL contained by the new window. If URL is an empty string, a new, empty window is created.

    windowFeatures is an optional, comma-separated list of options for the new window. The boolean windowFeatures options are set to true if they are specified without values, or as yes or 1. For example, open("", "messageWindow", "toolbar") and open("", "messageWindow", "toolbar=1") both set the toolbar option to true. If windowName does not specify an existing window and you do not specify windowFeatures, all boolean windowFeatures are true by default.

    Following is a description of the windowFeatures:

  • toolbar creates the standard Navigator toolbar, with buttons such as "Back" and "Forward", if true
  • location creates a Location entry field, if true
  • directories creates the standard Navigator directory buttons, such as "What's New" and "What's Cool", if true
  • status creates the status bar at the bottom of the window, if true
  • menubar creates the menu at the top of the window, if true
  • scrollbars creates horizontal and vertical scrollbars when the document grows larger than the window dimensions, if true
  • resizable allows a user to resize the window, if true
  • copyhistory gives the new window the same session history as the current window, if true
  • width specifies the width of the window in pixels
  • height specifies the height of the window in pixels

    Description for document

    Description to be supplied.

    Applies to

    document, window

    Examples

    In the following example, the windowOpener function opens a window and uses write methods to display a message:

    function windowOpener() {
   msgWindow=open("","Display window","toolbar=no,directories=no,menubar=no");
   msgWindow.document.write("<HEAD><TITLE>Message window</TITLE>");
   msgWindow.document.write("<CENTER><BIG><B>Hello, world!</B>");
}

    The following is an onClick event handler that opens a new client window displaying the content specified in the file sesame.html. It opens it with the specified option settings and names the corresponding window object newWin.

    <FORM NAME="myform">
<INPUT TYPE="button" NAME="Button1" VALUE="Open Sesame!"
onClick="window.open('sesame.html', 'newWin',
'toolbar=no,directories=no,menubar=no,status=yes,width=300,height=300')">
</form>

    Notice the use of single quotes (') inside the onClick event handler.

    See also

  • close method

    parse method

    Syntax

    Date.parse(date string)

    Description

    The parse function takes a date string (such as "Dec 25, 1995"), and returns the number of milliseconds since January 1, 1970 00:00:00 (local time). This function is useful for setting date values based on string values, for example in conjunction with the setTime method.

    Given a string representing a time, parse returns the time value. It accepts the IETF standard date syntax: "Mon, 25 Dec 1995 13:30:00 GMT". It understands the continental US time zone abbreviations, but for general use, use a time zone offset, for example "Mon, 25 Dec 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.

    The parse function is a static method of Date. That means that you always use it as Date.parse(), rather than as a method of a date object you created.

    Applies to

    Date

    Examples

    If IPOdate is an existing date object, then

    IPOdate.setTime(Date.parse("Aug 9, 1995"))

    See also

  • UTC method

    pow method

    Returns arg1 to the arg2 power, i.e. arg1arg2.

    Syntax

    pow(arg1, arg2)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • sqrt method

    prompt method

    Displays an Prompt dialog box with a message and an input field

    Syntax

    prompt(message, input default)

    Description

    Use the prompt method to display a dialog box that takes user input. The arguments, message and input default are JavaScript values to be displayed as the message and the default value in the input field, respectively.

    Applies to

    window

    Examples

    prompt("Enter the number of doughnuts you want:", 12)

    See also

  • alert, confirm methods

    random method

    Returns a pseudo-random number between zero and one. xxx NYI.

    Syntax

    xxx To be supplied.

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    round method

    Returns its argument, rounded to the nearest integer. In other words, if its argument is n.5 or greater (where n is an integer), returns n+1, otherwise returns n.

    Syntax

    round(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    select method

    For password, text, and textArea, selects the input area of the object.

    Syntax

    select()

    Description

    Use the select method to highlight the input area of a form element. You can use the select method with the focus method to highlight a field and position the cursor for a user response.

    Applies to

    password, text, textArea

    Examples

    In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the select method highlights the password field and focus method returns focus to it so the user can re-enter the password.

    function checkPassword(userPass) {
   if (badPassword) {
      alert("Please enter your password again.")
      userPass.focus()
      userPass.select()
   }
}
    This example assumes that the password is defined as:
    <INPUT TYPE=password NAME=userPass>

    See also

  • blur, focus methods

    setDate method

    Syntax

    dateObj.setDate(day)

    where dateObj is a date object.

    Description

    Sets the day of the month for the date object. The argument is an integer from 1 to 31.

    Applies to

    Date

    Examples

    The second statement below changes the day for theBigDay to the 24th of July from its original value.

    theBigDay = new Date("July 27, 1962 23:30:00")
Xmas95.setDate(24)

    See also

  • xxx To be supplied.

    setHours method

    Syntax

    dateObj.setHours(hours

    where dateObj is a date object.

    Description

    Sets the hours in the current time. The argument is an integer between 0 and 23.

    Applies to

    Date

    Examples

    theBigDay.setHours(7)

    See also

  • xxx To be supplied.

    setMinutes method

    Syntax

    dateObj.setMinutes(minutes)

    where dateObj is a date object.

    Description

    Sets the minutes in the current time. The argument is an integer between 0 and 59.

    Applies to

    Date

    Examples

    theBigDay.setMinutes(45)

    See also

  • xxx To be supplied.

    setMonth method

    Syntax

    dateObj.setMonth(month)

    where dateObj is a date object.

    Description

    Sets the month in the current date. The argument is an integer between 0 and 11.

    Applies to

    Date

    Examples

    theBigDay.setMonth(6)

    See also

  • xxx To be supplied.

    setSeconds method

    Syntax

    dateObj.setSeconds(seconds)

    where dateObj is a date object.

    Description

    Sets the seconds in the current time. The argument is an integer between 0 and 59.

    Applies to

    Date

    Examples

    theBigDay.setSeconds(30)

    See also

  • xxx To be supplied.

    setTime method

    Syntax

    dateObj.setTime(timevalue)

    where dateObj is a date object.

    Description

    Sets the value of the date object. This argument is the number of milliseconds since the epoch (1 January 1970 00:00:00) You can use this method to help assign a date and time to another date object.

    Applies to

    Date

    Examples

    theBigDay = new Date("July 1, 1999")
sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime())

    setTimeout method

    Evaluates an expression after a specified number of milliseconds have elapsed.

    Syntax

    timeoutID=setTimeout(expression, msec)

    expression is a string expression.
    msec is a numeric value or numeric string in millisecond units.
    timeoutID is an identifier that is used only to cancel the evaluation with the clearTimeout method.

    Description

    xxx Description to be supplied. Applies to

    window

    Examples

    xxx Examples to be supplied.

    See also

  • clearTimeout

    setYear method

    Syntax

    dateObj.setYear(year)

    where dateObj is a date object.

    Description

    Sets the year in the current date. Takes as its argument an integer greater than 1900.

    Applies to

    Date

    Examples

    theBigDay.setYear(96)

    See also

  • xxx To be supplied.

    sin method

    Returns the sine of its argument. The argument is in radians.

    Syntax

    sin(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • acos, asin, atan, cos, tan methods

    small method

    Causes the calling string object to be displayed in small font by surrounding it with HTML small font tags, <SMALL>....

    Syntax

    small()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • big, fontsize methods

    sqrt method

    Returns the square root of its argument.

    Syntax

    sqrt(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • pow method

    strike method

    Causes the calling string object to be displayed as struck out text, by surrounding it with HTML strikeout tags, <STRIKE> ... </STRIKE>.

    Syntax

    strike()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • blink, bold, italics methods

    sub method

    Causes the calling string object to be displayed as a subscript by surrounding it with HTML subscript tags, <SUB> ... </SUB>.

    Syntax

    sub()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    sup method

    submit method

    Submits the form.

    Syntax

    submit()

    Description

    xxx Description to be supplied.

    Applies to

    form

    Examples

    xxx Examples to be supplied.

    substring method

    The substring method returns a subset of a string object. If a < b, then it returns the subset starting at character a and ending before character b, considering the first character of the string to be character zero (0). If a > b, then it returns the subset starting at character b and ending at character a. If a = b, then it returns the empty string.

    Syntax

    substring(a, b)

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    If string x is "netscape" then x.substring(0,3) or x.substring(3,0) returns "net", and x.substring(4,7) or x.substring(7,4) returns "cap".

    sup method

    Causes the calling string object to be displayed as a superscript by surrounding it with HTML superscript tags, <SUP> ... </SUP>.

    Syntax

    sup()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    xxx Examples to be supplied.

    See also

  • sub method

    tan method

    Returns the tangent of its argument. The argument is in radians.

    Syntax

    tan(arg)

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    See also

  • acos, asin, atan, cos, sin methods

    toGMTString method

    Syntax

    dateObj.toGMTString()

    where dateObj is a date object.

    Description

    Converts a date to a String, using the Internet GMT conventions.

    Applies to

    Date

    Examples

    today.toGMTString()

    If today is a date object, then toGMTString would convert the date to GMT (UTC) using the operating system's time zone offset, and return a string value in the following form:
    Mon, 18 Dec 1995 17:28:35 GMT

    toLocaleString method

    Syntax

    dateObj.toLocaleString()

    where dateObj is a date object.

    Description

    Converts a date to a String, using the locale conventions.

    Applies to

    Date

    Examples

    today.toLocaleString()

    If today is a date object, then toLocaleString will return a string value in the following form:
    12/18/95 17:28:35

    toLowerCase method

    The toLowerCase method of string objects converts the string to all upper case.

    Syntax

    toLowerCase()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    For example, "ALPHABET".toLowerCase yields "alphabet".

    See also

  • toUpperCase method

    toString method

    For location, returns location.href, so you can use location as a string without typing ".href". For Date, converts a date to a string.

    Syntax

    toString()

    Description

    xxx Description to be supplied.

    Applies to

    location, Date methods

    Examples

    Here is an example of using toString with a date object, assuming theBigDay is a date object:

    theBigDay.toString()

    More Examples to be supplied.

    toUpperCase method

    The toUpperCase method of string objects converts the string to all upper case.

    Syntax

    toUpperCase()

    Description

    xxx Description to be supplied.

    Applies to

    string

    Examples

    For example, "alphabet".toUpperCase yields "ALPHABET".

    See also

  • toLowerCase method

    UTC method

    Syntax

    Date.UTC(year, month, mday [, hrs] [, min] [, sec])

    Description

    UTC takes comma-delimited date parameters and returns the number of milliseconds since January 1, 1970 00:00:00, Universal Coordinated Time (GMT). The arameters are:

    • year - a year after 1900
    • month - a month between 0-11
    • date - day of the month between 1-31
    • hrs - hours between 0-23
    • min - minutes between 0-59
    • sec - seconds between 0-59

    UTC is a static method of Date. That means that you always use it as Date.UTC(), rather than as a method of a date object you created.

    Applies to

    Date

    Examples

    The following statement creates a date object using GMT instead of local time:

    gmtDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0))

    See also

  • parse method

    write method

    Write HTML to the current window, in sequence with the HTML containing this SCRIPT. SCRIPTs have no effect on paragraphs or other structures in which they may occur.

    Syntax

    write()

    Description

    xxx Description to be supplied.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    See also

  • writeln method

    writeln method

    The same as write(), but adds a newline character. Note that this affects only preformatted text (inside a <PRE> or <XMP> tag).

    Syntax

    writeln()

    Description

    xxx Description to be supplied.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    See also

  • write method
    回主目录


JavaScript的对象

The following objects are available in JavaScript:
  • anchor
  • applet
  • button
  • checkbox
  • Date
  • document
  • form
  • history
  • link
  • location
  • Math
  • password
  • radioButton
  • reset
  • selection
  • string
  • submit
  • text
  • textArea
  • window

    • NOTE: Each object topic indicates whether the object is part of the client (in Navigator), server (in LiveWire), or is common (built-in to JavaScript). Server objects are not included in this version of the documentation.

    anchor object (client)

    An anchor is a piece of text identified as the target of a hypertext link.

    Syntax

    To define an anchor, use standard HTML syntax :

    <A NAME="anchorName"
   anchorText
</A>

    NAME specifies a tag that becomes an available hypertext target within the current document.
    anchorText specifies the text to display at the anchor.

    Description

    You can reference the anchor objects in your code by using the anchors property of the document object. The anchors property is an array that contains an entry for each anchor in a document.

    xxx to be supplied

    Properties

  • xxx to be supplied

    Methods

  • xxx to be supplied

    Event handlers

    None.

    Examples

    <A NAME="javascript_intro"><H2>Welcome to JavaScript</H2></A>

    See also

  • link object
  • anchors property

    applet object (client)

    Represents a Java applet. xxx NYI.

    Syntax

    xxx to be supplied

    Description

    The applet object executes applets written in Java, not JavaScript. Java applets execute only on Netscape 2.0 and HotJava, and only on 32-bit platforms, such as Windows 95, Windows NT, and Unix. They do not execute on the 16-bit Windows platforms, such as Windows 3.1.

    Properties

  • length

    Methods

  • xxx to be supplied

    Event handlers

  • xxx to be supplied

    Examples

    xxx to be supplied

    See also

  • xxx to be supplied

    button object (client)

    A button object is a pushbutton on an HTML form.

    Syntax

    <INPUT

   TYPE="button"
   NAME="objectName"
   VALUE="buttonText"
   [onClick="handlerText"]>
    NAME specifies the name of the button object as a property of the enclosing form object and can be accessed using the name property. VALUE specifies the label to display on the button face and can be accessed using the value property.

    Description

    The button object is a custom button that you can use to perform an action you define.

    Properties

  • name
  • value

    Methods

  • click

    Event handlers

  • onClick

    Examples

    A custom button does not necessarily load a new page into the client; it merely executes the script specified by the onClick event handler. In the following example, myfunction() is a JavaScript function.

    <INPUT TYPE="button" VALUE="Calculate" NAME="calc_button" onClick="myfunction(this.form)">

    See also

  • reset and submit objects

    checkbox object (client)

    A checkbox object is a checkbox on an HTML form. A checkbox is a toggle switch that lets the user set a value on or off.

    Syntax

    To define a checkbox, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT

   TYPE="checkbox"
   NAME="objectName"
   [CHECKED]
   [onClick="handlerText"]>

   textToDisplay

    Description

    Use the checked property to specify whether the checkbox is currently checked. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded.

    Properties

  • checked
  • defaultChecked
  • name
  • value

    Methods

  • click

    Event handlers

  • onClick

    Examples

    <B>Specify your music preferences (check all that apply):</B>
<BR><INPUT TYPE="checkbox" NAME="musicpref_rnb" CHECKED> R&B

<BR><INPUT TYPE="checkbox" NAME="musicpref_jazz" CHECKED> Jazz
<BR><INPUT TYPE="checkbox" NAME="musicpref_blues" CHECKED> Blues
<BR><INPUT TYPE="checkbox" NAME="musicpref_newage" CHECKED> New Age

    See also

  • xxx to be supplied

    Date object (common)

    JavaScript has a date object that enables you to work with dates and times. JavaScript handles dates very similar to the way Java handles dates: They have many of the same date methods, and both languages store dates internally as the number of milliseconds since January 1, 1970 00:00:00.

    Syntax

    To create a date object:

    varName = new Date(parameters)
    where varName is a JavaScript variable name for the date object being created; it can be a new object or a property of an existing object.

    The parameters for the Date constructor can be any of the following:

    • Nothing: creates today's date and time. For example, today = new Date()
    • A string representing a date in the following form: "Month day, year hours:minutes:seconds". For example, Xmas95= new Date("December 25, 1995 13:30:00") If you omit hours, minutes, or seconds, the value will be set to zero.
    • A set of integer values for year, month, and day. For example, Xmas95 = new Date(95,11,25)
    • A set of values for year, month, day, hour, minute, and seconds For example, Xmas95 = new Date(95,11,25,9,30,0)

    To use date methods:

    dateObj.methodName(parameters)

    Exceptions: The UTC and parse methods of date are static methods that you use as follows:

    Date.UTC(params)
Date.parse(params)

    Description

    JavaScript does not have a date data type. However, the date object and its methods enable you to work with dates and times in your applications.

    The date object has a large number of methods for setting, getting, and manipulating dates.

    Properties

    None.

    Methods

  • getDate
  • getDay
  • getHours
  • getMinutes
  • getMonth
  • getSeconds
  • getTime
  • getTimeZoneoffset
  • getYear
  • parse
  • setDate
  • setHours
  • setMinutes
  • setMonth
  • setSeconds
  • setYear
  • toString
  • toGMTString
  • toLocaleString
  • UTC

    Event handlers

    None. Built-in objects do not have event handlers.

    Examples

    xxx to be supplied

    See also

  • xxx to be supplied

    document object (client)

    The document object contains information on the current document.

    Syntax

    To define a document object, use standard HTML syntax with the addition of the onLoad and onUnLoad event handlers:

    <BODY

   BACKGROUND="backgroundImage"
   BGCOLOR="#backgroundColor"
   FGCOLOR="#foregroundColor"
   LINK="#unfollowedLinkColor"
   ALINK="#activatedLinkColor"
   VLINK="#followedLinkColor"
   [onLoad="handlerText"]
   [onUnLoad="handlerText"]>

</BODY>

    BGCOLOR, FGCOLOR, LINK, ALINK, and VLINK are color names or color specifications in the format "#rrggbb".

    Description

    The <BODY>... tag encloses an entire document, which is defined by the current URL. The entire body of the document (all other HTML elements for the document) goes within the <BODY>... tag.

    You can reference the anchors, forms, and links of a document by using the anchors, forms, and links properties. These properties are arrays that contain an entry for each anchor, form, or link in a document.

    The document object's title property reflects the contents of <TITLE>.... Other properties reflect the contents of the document; for example, bgColor reflects the background color, and lastModified reflects the time last modified. Some of the properties are reflections from HTML attributes; for example, the links property is a reflection of all the links in the document, and the forms property is a reflection of all the forms in the document.

    Properties

  • alinkColor
  • anchors
  • bgColor
  • fgColor
  • forms
  • lastModified
  • linkColor
  • links
  • loadedDate
  • location
  • referrer
  • title
  • vlinkColor

    Methods

  • clear
  • close
  • open
  • write
  • writeln

    Event handlers

  • onLoad
  • onUnLoad

    Examples

    xxx to be supplied

    See also

  • window object

    form object (client)

    A form lets users input text and make choices from form objects such as checkboxes, radio buttons, and selection lists. You can also use a form to post data to or retrieve data from a server.

    Syntax

    To define a form, use standard HTML syntax with the addition of the onSubmit event handler:

    <FORM

   NAME="objectName
   TARGET="windowName"
   ACTION="serverURL"
   METHOD=GET | POST
   [onSubmit="handlerText"]>

</FORM>

    TARGET specifies the window that form responses go to. When you submit a form with a TARGET attribute, instead of seeing the server's responses in the same window that contained the form, you see them in a (possibly new) window.
    ACTION specifies the URL of the server to which form field input information is sent. METHOD specifies how information is sent to the server specified by ACTION. GET (the default) appends the input information to the URL which on most receiving systems becomes the value of the environment variable QUERY_STRING. POST sends the input information in a data body which is available on stdin with the data length set in the environment variable CONTENT_LENGTH.

    Description

    Each form in a document corresponds to a distinct object.

    You can reference the form objects in your code by using the forms property of the document object. The forms property is an array that contains an entry for each form in a document.

    You can reference a form's elements in your code by using the elements property. The elements property is an array that contains an entry for each element (such as a checkbox, radioButton, or text object) in a form.

    Properties

  • action
  • elements
  • method
  • name
  • target

    Methods

  • submit

    Event handlers

  • onSubmit

    Examples

    xxx to be supplied

    See also

  • elements, forms properties

    history object (client)

    The history object contains information on the URLs that the client has visited. This information is stored in a history list, and is accessible through the Navigator's Go menu.

    Syntax

    history.go(delta)
    delta is an integer representing the offset of the destination URL in the history list.

    Description

    The history object is a linked list of URLs the user has visited, as shown in the Navigator's Go menu.

    Properties

  • current
  • length

    Methods

  • back
  • forward
  • go

    Event handlers

    None.

    Examples

    The following example goes to the URL the user visited three clicks ago.

    history.go(-3)

    See also

  • xxx to be supplied

    link object (client)

    A link is a piece of text identified as a hypertext link. When the user clicks the link text, the link hypertext reference is loaded into its target window.

    Syntax

    To define a link, use standard HTML syntax with the addition of the onClick and onMouseOver event handlers:

    <A HREF=locationOrURL
   TARGET="windowName"
   [onClick="handlerText"]
   [onMouseOver="handlerText"]>

   linkText
</A>

    HREF identifies a destination anchor or URL.
    TARGET specifies the window that the link is loaded into.
    linkText is rendered as a hypertext link to the URL.

    Description

    Each link object is a location object.

    You can reference the link objects in your code by using the links property of the document object. The links property is an array that contains an entry for each link in a document.

    Properties

  • target

    Methods

  • xxx to be supplied

    Event handlers

  • onClick
  • onMouseOver

    Examples

    The following example creates a hypertext link to an anchor named javascript_intro.

    <A HREF="#javascript_intro">Introduction to JavaScript</A>

    The following example creates a hypertext link to a URL.

    <A HREF="../../tppmsgs/msgs0.htm#2" tppabs="http://www.netscape.com/">Netscape Home Page</A>

    See also

  • anchor object
  • links property

    location object (client)

    The location object contains information on the current URL.

    Syntax

    location.property
    property is one of the properties listed below.

    Description

    xxx to be supplied

    Properties

  • hash
  • host
  • hostname
  • href
  • pathname
  • port
  • protocol
  • search

    Methods

  • assign
  • toString

    Event handlers

    None.

    Examples

    xxx to be supplied

    See also

  • xxx to be supplied

    Math object (common)

    The built-in Math object has properties and methods for mathematical constants and functions. For example, the Math object's PI property has the value of pi.

    Syntax

    Math.propertyName
or
Math.methodName(parameters)

    Description

    You reference the constant PI as Math.PI. Constants are defined with the full precision of real numbers in JavaScript.

    Similarly, you reference Math functions as methods. For example, the sine function is Math.sin(argument), where argument is the argument.

    It is often convenient to use the with statement when a section of code uses several Math constants and methods, so you don't have to type "Math" repeatedly. For example,

    with Math {
   a = PI * r*r;
   y = r*sin(theta)
   x = r*cos(theta)
}

    Properties

  • E
  • LN10
  • LN2
  • PI
  • SQRT1_2
  • SQRT2

    Methods

  • abs
  • acos
  • asin
  • atan
  • ceil
  • cos
  • exp
  • floor
  • log
  • max
  • min
  • pow
  • random
  • round
  • sin
  • sqrt
  • tan

    Event handlers

    None. Built-in objects do not have event handlers.

    Examples

    xxx to be supplied

    See also

  • xxx to be supplied

    password object (client)

    A password object is a text field on an HTML form. When the user enters text into the field, asterisks (*) hide anything entered from view.

    Syntax

    To define a password object, use standard HTML syntax:

    <INPUT

   TYPE="password"
   NAME="objectName"
   [VALUE="textValue"]
   SIZE=integer

    Description

    xxx to be supplied

    Properties

  • defaultValue
  • name
  • value

    Methods

  • focus
  • blur
  • select

    Event handlers

    None.

    Examples

    <B>Password:</B> <INPUT TYPE="password" NAME="password" VALUE="" SIZE=25>

    See also

  • xxx to be supplied

    radioButton object (client)

    A radioButton object is a set of radio buttons on an HTML form. A set of radio buttons lets the user choose one item from a list.

    Syntax

    To define a set of radio buttons, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT

   TYPE="radio"
   NAME="objectName"
   VALUE="buttonValue"
   [CHECKED]
   [onClick="handlerText"]>

   textToDisplay

    NAME should contain the same value for all radio buttons in a group.

    Description

    All radio buttons in a radio button group use the same name property. To access the individual radio buttons in your code, follow the object name with an index starting from zero, one for each button the same way you would for an array such as forms: document.forms[0].objectName[0] is the first, document.forms[0].objectName[1] is the second, etc.

    Properties

  • checked
  • defaultChecked
  • index
  • length
  • name
  • value

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example defines a radio button group to choose among three catalogs. Each radio button is given the same name, NAME="choice", forming a group of buttons for which only one choice can be selected. The example also defines a text field that defaults to what was chosen via the radio buttons but that allows the user to type a nonstandard catalog name as well. JavaScript automatically sets the catalog name input field based on the radio buttons.

    <INPUT TYPE="text" NAME="catalog" SIZE="20">
<INPUT TYPE="radio" NAME="choice" VALUE="PRICEY"
   onClick="form.catalog.value = 'top-of-the-line'"> It's really great!
<INPUT TYPE="radio" NAME="choice" VALUE="MODEST"
   onClick="form.catalog.value = 'middle-of-the-road'"> It's pretty good.
<INPUT TYPE="radio" NAME="choice" VALUE="CHEAPO"
   onClick="form.catalog.value = 'bargain-basement'"> It stinks!

    See also

  • selection object

    reset object (client)

    A reset object is a reset button on an HTML form.

    Syntax

    To define a reset button, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT

   [NAME="objectName"]
   TYPE="reset"
   VALUE="buttonText"
   [onClick="handlerText"]>
    VALUE specifies the text to display on the button face and can be accessed using the value property.

    Description

    A reset button resets all elements in a form to their defaults.

    Properties

  • name
  • value

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example displays a text object containing "CA". If the user types a different state abbreviation in the text object and then clicks the Clear Form button, the original value of "CA" is restored.

    <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> <P><INPUT TYPE="reset" VALUE="Clear Form">

    See also

  • button and submit objects

    selection object (client)

    A selection object is a selection list or scrolling list on an HTML form. A selection list lets the user choose one item from a list. A scrolling list lets the user choose one or more items from a list.

    Syntax

    To define a selection object, use standard HTML syntax with the addition of the onBlur, onChange, and onFocus event handlers:

    <SELECT

   NAME="objectName"
   [SIZE="value"]
   [MULTIPLE]
   [onBlur="handlerText"]
   [onChange="handlerText"]
   [onFocus="handlerText"]>

   <OPTION [SELECTED]> textToDisplay [ ... <OPTION> textToDisplay]
</SELECT>

    SIZE specifies the number of options visible when the form is displayed.

    Description

    You can reference the options of a selection object in your code by using the options property. The options property is an array that contains an entry for each option in a selection object. Each option has the properties listed below.

    The options on selection objects can be updated dynamically. xxx NYI.

    Properties

    The selection object has the following properties:

  • options
  • selectedIndex

    The options property has the following properties:

  • defaultSelected
  • index
  • selected
  • text
  • value

    Methods

  • click

    Event handlers

  • onBlur
  • onChange
  • onFocus

    Examples

    The following example displays a selection list.

    Choose the music type for your free CD: <SELECT NAME="music_type_single"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age</SELECT> <P>Choose the music types for your free CDs: <BR><SELECT NAME="music_type_multi" MULTIPLE> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age</SELECT>

    See also

  • radioButton object
  • options property

    string object (common)

    A string object consists of a series of characters.

    Syntax

    stringName.property|method
    stringName is the name of a string variable.
    property is one of the properties listed below.
    method is one of the methods listed below.

    Description

    A string can be represented as a literal enclosed by single or double quotes; for example, "Netscape" or 'Netscape'.

    Properties

  • length

    Methods

  • anchor
  • big
  • blink
  • bold
  • charAt
  • fixed
  • fontcolor
  • fontsize
  • indexOf
  • italics
  • lastIndexOf
  • link
  • small
  • strike
  • sub
  • substring
  • sup
  • toLowerCase
  • toUpperCase

    Event handlers

    None. Built-in objects do not have event handlers.

    Examples

    The following statement creates a string variable.

    var last_name = "Schaefer"

    last_name.length is 8.
    last_name.toUpperCase() is "SCHAEFER".
    last_name.toLowerCase() is "schaefer".

    See also

  • text and textArea objects

    submit object (client)

    A submit object is a submit button on an HTML form.

    Syntax

    To define a submit button, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT

   TYPE="submit"
   NAME="objectName"
   VALUE="buttonText"
   [onClick="handlerText"]>
    VALUE specifies the text to display on the button face and can be accessed using the value property.

    Description

    A submit button causes a form to be submitted.

    Clicking a submit button submits a form to the program specified by the form's action property. This action always loads a new page into the client; it may be the same as the current page, if the action so specifies or is not specified.

    Properties

  • name
  • value

    Methods

  • click

    Event handlers

  • onClick

    Examples

    <INPUT TYPE="submit" NAME="submit_button" VALUE="Done">

    See also

  • reset and button objects

    text object (client)

    A text object is a text input field on an HTML form. A text field lets the user enter a word, phrase, or series of numbers.

    Syntax

    To define a text object, use standard HTML syntax with the addition of the onBlur, on Change, onFocus, and onSelect event handlers:

    <INPUT

   TYPE="text"
   NAME="objectName"
   VALUE="textValue"
   SIZE=integer
   [onBlur="handlerText"]
   [onChange="handlerText"]
   [onFocus="handlerText"]
   [onSelect="handlerText"]>

    Description

    text objects can be updated dynamically by setting this.value

    xxx to be supplied

    Properties

  • defaultValue
  • name
  • value

    Methods

  • focus
  • blur
  • select

    Event handlers

  • onBlur
  • onChange
  • onFocus
  • onSelect

    Examples

    <B>Last name:</B> <INPUT TYPE="text" NAME="last_name" VALUE="" SIZE=25>

    See also

  • textArea and string objects

    textArea object (client)

    A textArea object is a multiline input field on an HTML form. A textArea field lets the user enter words, phrases, or numbers.

    Syntax

    To define a text area, use standard HTML syntax with the addition of the onBlur, onChange, onFocus, and onSelect event handlers:

    <TEXTAREA

   NAME="objectName"
   ROWS="integer"
   COLS="integer"
   [onBlur="handlerText"]
   [onChange="handlerText"]
   [onFocus="handlerText"]
   [onSelect="handlerText"]>

   textToDisplay
</TEXTAREA>

    textToDisplay allows only ASCII text, and new lines are respected.
    ROWS and COLS define the physical size of the displayed input field in numbers of characters.

    Description

    textArea objects can be updated dynamically. xxx need to explain how. (see text object)

    Properties

  • defaultValue
  • name
  • value

    Methods

  • focus
  • blur
  • select

    Event handlers

  • onBlur
  • onChange
  • onFocus
  • onSelect

    Examples

    <B>Description:</B> <BR><TEXTAREA NAME="item_description" ROWS=6 COLS=55> Our storage ottoman provides an attractive way to store lots of CDs and videos--and it's versatile enough to store other things as well. It can hold up to 72 CDs under the lid and 20 videos in the drawer below. </TEXTAREA>

    See also

  • text and string objects

    window object (client)

    A window object is the top-level object for each document, location, and history object group.

    Syntax

    xxx to be supplied

    Description

    The window object is the top-level object in the JavaScript client hierarchy. Because the existence of the current window is assumed, you don't have to reference the name of the window when you call its methods and assign its properties. For example, status="Jump to a new location" is a valid property assignment, and close() is a valid method call.

    The self and window properties are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling either window.close() or self.close(). You can use these properties to make your code more readable, or to disambiguate the property assignment self.status from a form called status.

    See the methods and properties listed below for more examples.

    You can reference a window's frame objects in your code by using the frames property. The frames property is an array that contains an entry for each frame in a window.

    Properties

  • frames
  • parent
  • self
  • top
  • status
  • defaultStatus

    Methods

  • alert
  • close
  • confirm
  • open
  • prompt
  • setTimeout
  • clearTimeout

    Event handlers

  • onLoad
  • onUnload

    Examples

    xxx to be supplied

    See also

  • frames property
    回主目录


JavaScript properties

JavaScript 的对象属性

以下的属性可在 JavaScript中用到:
  • action
  • alinkColor
  • anchors
  • bgColor
  • checked
  • current
  • defaultChecked
  • defaultSelected
  • defaultStatus
  • defaultValue
  • E
  • elements
  • fgColor
  • forms
  • frames
  • hash
  • host
  • hostname
  • href
  • index
  • lastModified
  • length
  • linkColor
  • links
  • LN2
  • LN10
  • loadedDate
  • location
  • method
  • name
  • options
  • parent
  • pathname
  • PI
  • port
  • protocol
  • referrer
  • search
  • selected
  • selectedIndex
  • self
  • SQRT1_2
  • SQRT2
  • status
  • target
  • text
  • title
  • top
  • value
  • vlinkColor
  • window

    • action property

    String value of a FORM tag's ACTION attribute.

    Applies to

    form

    Examples

    xxx Examples to be supplied.

    alinkColor property

    RGB value for color of activated links (after mouse-button down, but before mouse-button up), expressed as a hexadecimal triplet. This property is the JavaScript reflection of the ALINK attribute of the HTML BODY tag.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    anchors property

    Array of objects corresponding to named anchors (<A NAME=""> tags) in source order.

    The anchors array contains an entry for each anchor in a document. For example, if a document contains three anchors, these anchors are reflected as document.anchors[0], document.anchors[1], and document.anchors[2].

    To obtain the number of anchors in a document, use the length property: document.anchors.length.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    See also

  • length property

    bgColor property

    RGB value of background color, expressed as a hexadecimal triplet. This property is the JavaScript reflection of the BGCOLOR attribute of the HTML BODY tag.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    checked property

    For checkbox, Boolean, false if not checked, true if checked. For radioButton, Boolean, false if not pressed, true if pressed.

    Applies to

    checkbox, radioButton

    Examples

    xxx To be supplied.

    current property

    URL of current page. xxx Not yet implemented in Beta 4.

    Applies to

    history

    Examples

    xxx Examples to be supplied.

    defaultChecked property

    For checkbox, Boolean property that indicates if the element is selected by default, by the CHECKED attribute. For radioButton, Boolean property that indicates if the element is selected by default, by the CHECKED attribute.

    Applies to

    checkbox, radioButton

    Examples

    xxx Examples to be supplied.

    defaultSelected property

    Boolean property that indicates if the option is selected by default, by the presence of the SELECTED attribute in the HTML OPTION tag.

    Applies to

    selection

    Examples

    xxx Examples to be supplied.

    defaultStatus property

    For a window, the defaultStatus property reflects the default message displayed in the status bar at the bottom of the window. Do not confuse defaultStatus with status. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor.

    Applies to

    window

    Examples

    xxx Examples to be supplied.

    defaultValue property

    For text and textArea, string, the initial contents of the field.

    Applies to

    password, text, textArea

    Examples

    xxx Examples to be supplied.

    E property

    E is Euler's constant, the base of natural logarithms, roughly 2.718.

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    elements property (client)

     Array of objects corresponding to form elements (such as checkbox, radioButton, and text objects) in source order.

    The elements array contains an entry for each object in a form. For example, if a form has a text field, a radio button group, and a checkbox, these elements are reflected as formName.elements[0], formName.elements[1], and formName.elements[2].

    Applies to

    form

    Examples

    xxx Examples to be supplied.

    fgColor property

    RGB value of foreground (text) color, expressed as a hexadecimal triplet. This property is the JavaScript reflection of the FGCOLOR attribute of the HTML BODY tag.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    forms property

    Array of objects corresponding to named forms (<FORM NAME=""> tags) in source order.

    The forms array contains an entry for each form object in a document. For example, if a document contains three forms, these forms are reflected as document.forms[0], document.forms[1], and document.forms[2].

    You can refer to a form's elements by using the forms array. For example, you would refer to a text object named quantity in the second form as:

    document.forms[1].quantity
    You would refer to the value property of this text object as:
    document.forms[1].quantity.value

    To obtain the number of forms in a document, use the length property: document.forms.length.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    See also

  • length property

    frames property

    Array of objects corresponding to child frame windows (<FRAMESET> tag) in source order.

    The frames array contains an entry for each child frame in a window. For example, if a window contains three child frames, these frames are reflected as window.frames[0], window.frames[1], and window.frames[2].

    To obtain the number of number of child frames in a window, use the length property: window.frames.length.

    Applies to

    window

    Examples

    xxx Examples to be supplied.

    See also

  • length property

    hash property

    The anchor name following the # symbol.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    host property

    The hostname:port part of the location or URL.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    See also

  • hostname

    hostname property

    The hostname part of the location or URL.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    See also

  • host

    href property

    The entire URL as a JavaScript string.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    index property

    For radioButton, number, the ordinal number of the radioButton field, 0-based. For a select object option, the number identifying the position of the option in the selection, starting from zero.

    Applies to

    radioButton, selection

    Examples

    xxx Examples to be supplied.

    lastModified property

    A string containing the last-modified date.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    length property

    For a history object, the length of the history list. For a string object, the integer length of the string. For a radioButton object, the number of radio buttons in the object. For an anchors, forms, frames, links, or options array, the number of elements in the array.

    For a null string, length is zero.

    Applies to

  • applet, history, radioButton, string objects
  • anchors, forms, frames, links, options properties

    Examples

    xxx Example with history to be supplied.

    If the string object mystring is "netscape", then mystring.length returns the integer 8.

    If the current document contains five forms, then document.forms.length returns the integer 5.

    linkColor property

    RGB value for color of hyperlinks, expressed as a hexadecimal triplet.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    links property

    Array of objects corresponding to link objects (<A HREF=URL> tags) in source order.

    The links array contains an entry for each link object in a document. For example, if a document contains three link objects, these links are reflected as document.links[0], document.links[1], and document.links[2].

    To obtain the number of links in a document, use the length property: document.links.length.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    See also

  • length property

    LN2 property

    LN2 is the natural logarithm of two, roughly 0.693.

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    LN10 property

    LN10 is the natural logarithm of ten, roughly 2.302.

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    loadedDate property

    xxx Description to be supplied. Not yet implemented in Beta 4.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    location property

    The full URL of the document.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    method property

    Value of METHOD attribute, "get" or "post".

    Applies to

    form

    Examples

    xxx Examples to be supplied.

    name property

    A string whose value is the same as the NAME attribute of the object. Note that for button, reset, and submit objects, this is the internal name for the button, not the label that appears onscreen.

    Applies to

    button, checkbox, form, password, radioButton, reset, submit, text, textArea

    Examples

    xxx Examples to be supplied.

    options property

    Array of objects corresponding to options in a selection object (<OPTION> tags) in source order.

    The options array contains an entry for each option in a selection object. For example, if a selection object named musicStyle contains three options, these options are reflected as musicStyle.options[0], musicStyle.options[1], and musicStyle.options[2].

    To obtain the number of options in a selection object, use the length property: objectName.options.length.

    Applies to

    selection

    Examples

    xxx Examples to be supplied.

    See also

  • length property

    parent property

    In a <FRAMESET> and <FRAME> relationship, the <FRAMESET> window.

    Applies to

    window

    Examples

    xxx Examples to be supplied.

    pathname property

    The file or object path name following the third slash.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    PI property

    Pi is the ratio of the circumference of a circle to its diameter, roughly 3.1415.

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    port property

    The port number in a URL, if any; otherwise "".

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    protocol property

    The initial substring up to and including the first colon, which indicates the URL's access method.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    referrer property

    xxx Description to be supplied.

    Applies to

    document

    Examples

    xxx Examples to be supplied.

    search property

    Any query string or form data after ?.

    Applies to

    location

    Examples

    xxx Examples to be supplied.

    selected property

    Boolean property that indicates the current selected state of an option in a select object.

    Applies to

    selection

    Examples

    xxx Examples to be supplied.

    selectedIndex property

    xxx to be described

    Applies to

    selection

    Examples

    xxx Examples to be supplied.

    self property

    The self property refers to the current window. Use the self property to disambiguate a window property from a form of the same name. You can also use the self property to make your code more readable.

    Applies to

    window

    Examples

    In the following example, self.status is used to set the status property. This usage disambiguate the status property of a window from a form called "status".

    <A HREF=""
   onClick="this.href=pickRandomURL();"
   onMouseOver="self.status='Pick a random URL' ; return true">
Go!</A>

    See also

  • window property

    SQRT1_2 property

    SQRT1_2 is the square root of one-half; equivalently, one over the square root of two, roughly 0.707.

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    SQRT2 property

    SQRT2 is the square root of two, roughly 1.414.

    Applies to

    Math

    Examples

    xxx Examples to be supplied.

    status property

    For a window, the status property reflects a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor. Do not confuse status with defaultStatus. The defaultStatus property reflects the default message displayed in the status bar.

    Applies to

    window

    Examples

    Suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property:

    <A HREF=""
   onClick="this.href=pickRandomURL();"
   onMouseOver="self.status='Pick a random URL'; return true">
Go!</A>

    In the above example, the status property of the window is assigned to the window's self property, as self.status. As this example shows, you must return true to set the status property in the onMouseOver event handler.

    target property

    Window targeted for form response after the form has been submitted.

    Applies to

    form, link

    Examples

    xxx Examples to be supplied.

    text property

    String, reflection of the text after the <OPTION> tag.

    Applies to

    selection

    Examples

    xxx Examples to be supplied.

    title property

    Current document title.

    Applies to

    document

    Examples

    xxx Examples to be supplied.


JavaScript 的语法

JavaScript statements consist of keywords used with the appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semi-colon.

Syntax conventions: All keywords in syntax statements are in bold. Words in italics represent user-defined names or statements. Any portions enclosed in square brackets, i.e. [ and ], are optional. {statements} indicates a block of statements, which can consist of a single statement or multiple statements delimited by a curly braces.

The following statements are available in JavaScript:
  • break
  • comment
  • continue
  • for
  • for...in
  • function
  • if...else
  • return
  • var
  • while
  • with

    • break statement

    The break statement terminates the current while or for loop and transfers program control to the statement following the terminated loop.

    Syntax

    break

    Examples

    The following function has a break statement that terminates the while loop when i is 3, and then returns the value 3 * x.

    function func(x) {
    var i = 0;
    while (i < 6) {
        if (i == 3)
            break;
        i++;
    }
    return i*x;
}

    comment statement

    Comments are notations by the author to explain what the script does, and they are ignored by the interpreter. JavaScript supports Java-style comments:

  • Comments on a single line are preceded by a double-slash (//).
  • Comments that span multiple lines are preceded by a /* and followed by a */.

    Syntax

    1. // comment text
2. /* multiple line comment text */

    Examples

    // This is a single-line comment.

    /* This is a multiple-line comment. It can be of any length, and
you can put whatever you want here. */

    continue statement

    The continue statement terminates execution of the block of statements in a while or for loop, and continues execution of the loop with the next iteration. In contrast to the break statement, it does not terminate the execution of the loop entirely: instead,

    • In a while loop it jumps back to the condition.
    • In a for loop it jumps to the update expression.

    Syntax

    continue

    Examples

    The following example shows a while loop that has a continue statement that executes when the value of i is 3. Thus, n takes on the values 1, 3, 7, and 12.

    i = 0;
n = 0;
while (i < 5) {
    i++;
    if (i == 3)
        continue;
    n += i;
}

    for statement

    A for loop consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a block of statements executed in the loop. The parts of the for statement are:

    • The initial expression, generally used to initialize a counter variable. This statement may optionally declare new variables with the var keyword. This expression is optional.
    • The condition that is is evaluated on each pass through the loop. If this condition is true, the statements in the succeeding block are performed. This conditional test is optional. If omitted, then the condition always evaluates to true.
    • An update expression generally used to update or increment the counter variable. This expression is optional.
    • A block of statements that are executed as long as the condition is true. This can be a single statement or multiple statements. Although not required, it is good practice to indent these statements four spaces from the beginning of the for statement.

    Syntax

    for ([initial expression]; [condition]; [update expression]) {
    statements
}
initial expression = statement | variable declartion

    Examples

    This simple for statement starts by declaring the variable i and initializing it to zero. It checks that i is less than nine, and performs the two succeeding statements, and increments i by one after each pass through the loop.

    for (var i = 0; i < 9; i++) {
    n += i;

    myfunc(n);
}

    for...in statement

    The for statement iterates variable var over all the properties of object obj. For each distinct property, it executes the statements in statements.

    Syntax

    for (var in obj) {
    statements }

    Examples

    The following function takes as its argument an object and the object's name. It then iterates over all the object's properties and returns a string that lists the property names and their values.

    function dump_props(obj, obj_name) {
    var result = "", i = "";
    for (i in obj)
        result += obj_name + "." + i + " = " + obj[i] + "\n";
    return result;
}

    function statement

    The function statement declares a JavaScript function name with the specified parameters param. To return a value, the function must have a return statement that specifies the value to return. You cannot nest a function statement in another statement or in itself.

    All parameters are passed to functions, by value. In other words, the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function.

    Syntax

    function name([param] [, param] [..., param]) {
    statements }

    Examples

    //This function returns the total dollar amount of sales, when
//given the number of units sold of products a, b, and c.
function calc_sales(units_a, units_b, units_c) {
    return units_a*79 + units_b*129 + units_c*699
}

    if...else statement

    The if...else statement is a conditional statement that executes the statements in statements if condition is true. In the optional else clause, it executes the statements in else statements if condition is false. These may be any JavaScript statements, including further nested if statements.

    Syntax

    if (condition) {
    statements
} [else {
    else statements
}]

    Examples

    if ( cipher_char == from_char ) {
    result = result + to_char;
    x++
} else
    result = result + clear_char;

    return statement

    The return statement specifies the value to be returned by a function.

    Syntax

    return expression;

    Examples

    The following simple function returns the square of its argument, x, where x is an number.

    function square( x ) {
    return x * x;
}

    var statement

    The var statement declares a variable varname, optionally initializing it to have value. The variable name varname can be any legal identifier, and value can be any legal expression. The scope of a variable is the current function or, for variables declared outside a function, the current application.

    Using var outside a function is optional; you can declare a variable by simply assigning it a value. However, it is good style to use var, and it is neccessary in functions if there is a global variable of the same name. So, in general, it is a good idea to always use var, but you should definitely use it when declaring a local variable in a function, to ensure that any global variable of the same name does not override it.

    Syntax

    var varname [= value] [..., varname [= value] ]

    Examples

    var num_hits = 0, cust_no = 0

    while statement

    The while statement is a loop that evaluates the expression condition,and if it is true, executes statements. It then repeats this process, as long as condition is true. When condition evaluates to false, execution continues with the next statement following the statements.

    Although not required, it is good practice to indent the statements a while loop four spaces from the beginning of the for statement.

    Syntax

    while (condition) {
    statements
}

    Examples

    The following simple while loop iterates as long as n is less than three. Each iteration, it increments n and adds it to x. Therefore, x and n take on the following values

    • After first pass: x = 1 and n = 1
    • After second pass: x = 2 and n = 3
    • After third pass: x = 3 and n = 6

    After completing the third pass, the condition n < 3 is no longer true, so the loop terminates.

    n = 0;
x = 0;
while( n < 3 ) {
    n ++; x += n;
}

    with statement

    The with statement establishes object as the default object for the statements. Any property references without an object are then assumed to be for object. Note that the parentheses are required around object.

    Syntax

    with (object){
     statements
}

    Examples

    with (Math) {
    a = PI * r*r
    x = r * cos(theta)
    y = r * sin(theta)
}
    回主目录