0
var appsAndScopes=[
['1',['A','B','C','D']],
['2 ',['E','F','G','H']],
['3',['I']],
['4',['J']]
];
function getAllElements(id){return document.getElementById(id);}
function buildDropdowns(){
var applications=getAllElements('application').options; //Gets all applications names from appsAndScopes array.
for(var applicationsIndex=0;applicationsIndex<appsAndScopes.length;applicationsIndex++){
applications[applications.length]=new Option(appsAndScopes[applicationsIndex][0],appsAndScopes[applicationsIndex][0]);
}
getAllElements('application').onchange=function(){
this.blur();
var currentApplication=this.value;
if(!currentApplication){return;}
var scopes=getAllElements('scope').options;
scopes.length=1;
for(var scopesIndex=0;scopesIndex<appsAndScopes.length;scopesIndex++){
if(appsAndScopes[scopesIndex][0]!==currentApplication){continue;}
else{
var temp=appsAndScopes[scopesIndex][1];
for(var valueIndex=0;valueIndex<temp.length;valueIndex++){
scopes[scopes.length]=new Option(temp[valueIndex],temp[valueIndex]);
}
break;
}
}
}
}
$(function() {
buildDropdowns();
});
在該代碼中,我生成動態下拉菜單(即依賴下拉菜單)。此代碼工作正常。它使用2d數組來填充下拉列表的值。我想實現一個地圖而不是2d數組。這將改變整個迭代過程。
我對JavaScript很陌生。我不知道任何JavaScript的語法。請幫助我做到這一點。
你似乎不接受解決方案。當你接受解決方案時,你也會得到回購點。不接受解決方案不會鼓勵人們幫助你! –