如何将链接附加到单个数组项
How do I attach links to individual array items?
我已经工作了几个小时,试图让它工作。我想做的是:首先,有两个下拉菜单,第一个控制第二个。然后,我希望能够将每个单独的"第二选择"链接到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>
试试这个
<!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" : "http://www.abc.com",
"San Diego" : "http://www.abc.com",
"San Francisco" : "http://www.abc.com",
"Los Angeles" : "http://www.abc.com"};
firmwares[2] = {"Cleveland" : "http://www.abc.com",
"Akron" : "http://www.abc.com",
"Canton" : "http://www.abc.com",
"Cincinnati" : "http://www.abc.com",
"Columbus" : "http://www.abc.com"};
firmwares[3] = {"Philadelphia" : "http://www.abc.com",
"Pittsburgh" : "http://www.abc.com",
"Harrisburgh" : "http://www.abc.com"};
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(each));
nOption.setAttribute("value",each);
nList.appendChild(nOption);
}
document.getElementById("gotoCity").style.display = "none";
}
function openCity(firmware, city) {
var gotoCity = document.getElementById("gotoCity");
gotoCity.href = firmwares[firmware][city];
gotoCity.style.display="";
}
</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' onchange="openCity(this.form['phones'].value, this.value)" >
<option value="">Select Your City</option>
</select>
<a id="gotoCity" href="#" style="display:none;">Go</href>
</div>
</form>
</body>
</html>
相关文章:
- 在 laravel 4 上使用循环将数据数组存储到单个数组中
- 使用 lodash 是将数据从数组映射到单个数组的好方法
- 如何将链接附加到单个数组项
- 将培根流中的所有值合并到单个数组中
- 下划线模板,将列表添加到单个数组中
- 使用 JavaScript 将多个对象结果集的数组合并到单个数组中
- 如何旋转Javascript中表示为单个数组的4x8网格
- AngularJs过滤到单个数组元素并输出一个属性
- 将单个数组读取到存储中
- 根据id表将单个数组结果发送到打印机
- 将字符串收集到forEach内部的单个数组中
- 跟踪回调并将数据作为单个数组发送出去
- 使用lodash将重复对象合并到单个数组中
- 二维数组中单个数组的和
- 将多维数组转换为单个数组(Javascript)
- 从多个父元素中检索属性并将其存储到单个数组中
- 来自单个数组的目标对象值
- 通过单个数组递归记录javascript中所有可能的排列
- 使用javascript将单个数组转换为多维数组
- Javascript多维嵌套数组,在单个数组中排序