下表中给出了太阳系4个行星的部分数据,创建一个WEB页面,实现以下功能,当用户输入
星名后,单击按钮在对话框或页面的其他区域显示距离和直径
行星 离太阳的距离 直径
水星 3千6百万英里 3100英里
金星 6千7百万英里 7700英里
地球 9千3百万英里 7920英里
火星 1亿4千百万英里 4200英里
实现代码:
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
/>
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
<
script
language
="JavaScript"
type
="text/javascript"
>
...
var arrStarId=["水星","金星","地球","火星"];
var arrStarDetails=["离太阳的距离:3千6百万英里;直径:3100英里","离太阳的距离:6千7百万英里;直径:7700英里","离太阳的距离:9千3百万英里;直径:7920英里","离太阳的距离:1亿4千百万英里;直径:4200英里"];
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
function showDetails(element)...{ //用双数组方法
var value=element.value;
for(var i=0;i<arrStarId.length;i++)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if (arrStarId[i]===value) return alert(arrStarDetails[i])
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/0196c3df5ea9e936f21e9932cca91014.gif)
</
script
>
<
title
>
Test关联数组
</
title
>
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
<
style
type
="text/css"
>
...
<!--
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
.STYLE1 {...}{
color: #FF0000;
font-weight: bold;
}
-->
</
style
>
</
head
>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
body
>
<
form
id
="form1"
name
="form1"
method
="post"
action
=""
>
<
label
><
span
class
="STYLE1"
>
InputStar:
</
span
>
<
input
type
="text"
name
="InputStar"
/>
</
label
>
<
label
>
<
input
name
="SumbitStar"
type
="submit"
id
="SumbitStar"
value
="提交"
onclick
="javascript:showDetails(document.form1.InputStar)"
/>
</
label
>
</
form
>
</
body
>
</
html
>
通过定义两个数组关联
其它替换方法: