日期:2014-05-16  浏览次数:20280 次

这段代码中不明白的地方
大家好,本人刚学习JavaScript,从网上下载了一份文档,里面有很多错误,改了很多地方。下面的代码也是如此,也不知道改的对不对。也有不明白的地方,我列出了三点:
1. frames[1],form[0],goParam[1]都代表什么意思呀,为什么后面都要加上[0]或者[1]呢?
2. 代码里的 parent.frames[1].history.go(goVal) 不明白在这里是什么意思
3. 下面的代码里面不知道还有多少错误,我调试了一下,没找到错误,还请各位高手指教,谢谢。


<html>
<head>
<title>History对象</title>
</head>
<body bgcolor="#FFFFFF">
<SCRIPT LANGUAGE="JavaScript">
<!--
function goPrev(){
parent.frames[1].history.back()
}
function goNext(){
parent.frames[1].history.forward()
}
function moveOn(){
var urlAddress = ""
urlAddress = document.forms[0].LocationBox.value
if (urlAddress != ""){
parent.frames[1].location = urlAddress
document.forms[0].ListLen.value = parent.frames[1].history.length}
else{
alert("请在单击按钮之前输入文本信息.")
}
}
function jump(){
if (document.forms[0].goParam[1].checked){
var goVal = 0
goVal = parseInt(document.forms[0].GoBox.value)}
else{
var goVal = ""
goVal = document.forms[0].GoBox.value
parent.frames[1].history.go(goVal)
}
}
function getParentInfo(){
myParentTitle = parent.document.title
alert("myParentTitle")
}
// -->
</SCRIPT>
<form method="POST">
<h3><em>Ways to navigate</em></h3>
<ul>
<li>使用location对象.</li>
</ul>
<p><input type="text" size="20" maxlength="50" name="LocationBox"> <input type="button" value="查找" onClick="moveOn()"></p>
<ul>
<li>使用history对象的<em>back()</em> and<em> forward() </em>方法:</li>
</ul>
<p align=center><input type="button" value="&lt;&lt;" onClick="goPrev()"> <input type="button" value="&gt;&gt;" onClick="goNext()"></p>
<ul>
<li>使用history对象的<em>go()</em>方法:</li>
</ul>
<blockquote>
<p><input type="radio" name="goParam" value="ByCount">By Count <input type="radio" name="goParam" value="ByName">By Name <input type="text" size="20" maxlength="30" name="GoBox"></p>
<p><input type="button" value="Go" onClick="jump()"> History列表: <input type="text" size="3" maxlength="4" name="ListLen"> </p>
</blockquote>
<input type="button" value="取得信息" onClick="getParentInfo()">
</form>
</body>
</html>

------解决方案--------------------
[n]是集合按索引访问的方法,js,html中的集合都是从0开始的
frames就是页面上所有的的frameset和iframe的集合,frames[1]就是第二个frame/帧
forms就是本页中form/表单的集合,forms[0]就是第一个表单
对于form中的表单控件(input select textarea等),可以通过访问获得表单之后,继续用./点语法来访问他们
forms[0].goParam[1]就是第一个form中的名为goPara的第2个元素

parent.frames[1].history.go(goVal)就是控制父帧的第一个子帧向后退几步

你这个页里还有没有错误,不好意思,我没时间细看了,

如果你是初学者,我是建议你从最基本的东西学起,比如www.w3cschool.cn这个网站,HTML js基础之类。
你这个例子对于初学者是有点太复杂了。
------解决方案--------------------
[] 取数组 的元素

var arr=[1,2,3,4];
arr[0] 取 1; 表示数组第一个元素