function initArray() {
this.length = initArray.arguments.length
for (var i = 0; i p } this[i+1]="initArray.arguments[i]" 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
其原始码如下:
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) 代替.