我一直在努力工作数小时,试图让这个工作。我想要做的是: 首先,有两个下拉菜单,第一个控制第二个。 然后,我希望能够将每个单独的“第二选择”链接到href。 但是,“第二选择”在一个数组中,我不知道如何将它们访问到html中。请帮忙。如何将链接附加到单个数组项目?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Any Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var firmwares = [];
firmwares[1] = ["Sacramento","San Diego","San Francisco","Los Angeles"];
firmwares[2] = ["Cleveland","Akron","Canton","Cincinnati","Columbus"];
firmwares[3] = ["Philadelphia","Pittsburgh","Harrisburgh"];
firmwares[4] = [];
function fillSelect(nValue,nList){
nList.options.length = 1;
var curr = firmwares[nValue];
for (each in curr)
{
var nOption = document.createElement('option');
nOption.appendChild(document.createTextNode(curr[each]));
nOption.setAttribute("value",curr[each]);
nList.appendChild(nOption);
}
}
</script>
</head>
<body>
<form method="post" action="">
<div>
<select name='phones' onchange="fillSelect(this.value,this.form['firmwares'])">
<option value="">Select Your State</option>
<option value="1">California</option>
<option value="2">Ohio</option>
<option value="3">Pennsylvania</option>
<option value="4">Alaska</option>
</select>
<select name='firmwares' >
<option value="">Select Your City</option>
</select>
</div>
</form>
</body>
</html>
如果我理解正确的话,你要根据以往的下拉选项来显示第二个下拉?检查这个答案:[链接](http://stackoverflow.com/questions/6954556/show-a-second-dropdown-based-on-previous-dropdown-选择) – WhatisSober