我正在编写一个应该包含两个选择标签的 html。为了清楚起见,第一个选择标签包括大陆的名称,用户应该选择其中一个。第二个选择标签应在第一个选择标签中动态显示所选大陆的国家名称。谁能帮我理解我应该如何通过 JavaScript 函数来实现它?应该在第一个选择标签上设置什么事件?应该在选项或选择标签上设置事件吗?
<html lang="en">
<head>
<meta cahrset="utf-8">
<title>Java Script Question Exam</title>
<script type="text/javascript">
var la=["chili","castarica","cuba","jamaieca"];
var as=["Iran","Iraq","China","Japan"];
var eu=["Italy","France","Sweden"];
var af=["Egypt","Morocco"];
var continents=new Array(la,as,eu,af);
function ContinentFun(input)
{
var cont=document.getElementById("continent");
var selected=cont.options.selectedIndex;
var e=continents[selected];
var d = document.getElementById(input);
if(d.length==0)
{
for(var j=0; j<e.length;j++)
{
d.add(new Option(e[j],""));
}
}
else
{
if (d.length<e.length)
{
for(var i=0; i<d.length;i++)
{
d.options[i].text=e[i];
}
for(var j=d.length; j<e.length;j++)
{
d.add(new Option(e[j],""));
}
}
else
{
if(d.length>e.length)
{
for(var i=0; i<e.length;i++)
{
d.options[i].text=e[i];
}
for(var j=e.length; j<d.length;j++)
{
d.remove(j);
}
}
else
{
for(var i=0; i<e.length;i++)
{
d.options[i].text=e[i];
}
}
}
}
}
</script>
</head>
<body>
<form id="form1">
<table id="t1" border="2">
<tr>
<td>Select your Continent</td>
<td>
<select id="continent" size="1" onchange='ContinentFun("country")'>
<option>Latin America</option>
<option>Asia</option>
<option>Eroupa</option>
<option>Africa</option>
</select>
</td>
</tr>
<tr>
<td>Select Country</td>
<td>
<select id="country" size="1" width="15">
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" name="Send" value="Send" onclick='PrintInfo("continent","country","t1")' />
</td>
</tr>
</table>
<br><br><br>
<textarea id="t1">
</textarea>
</form>
</body>
</html>
它现在和我想要的一样好......