Javascript 如何为一个填充下拉列表附加一个使用不同数组的函数?
我有函数getRegionList()getLanguagesList()、两个单选按钮和一个下拉列表。问题是,当我单击第二个单选按钮时,这两个列表混淆在一起。如有任何建议,我将不胜感激。 [语言包含区域,但不应包含区域][1]Javascript 如何为一个填充下拉列表附加一个使用不同数组的函数?,javascript,html,dom,events,Javascript,Html,Dom,Events,我有函数getRegionList()getLanguagesList()、两个单选按钮和一个下拉列表。问题是,当我单击第二个单选按钮时,这两个列表混淆在一起。如有任何建议,我将不胜感激。 [语言包含区域,但不应包含区域][1] p2.className='btn-group2'; p2.innerHTML=' <label for="contactChoice3"> <input type="radio" id="rd1&qu
p2.className='btn-group2';
p2.innerHTML=' <label for="contactChoice3"> <input type="radio" id="rd1" onchange="f1()" name="search" > By Region</label>'+
' <label for="contactChoice3"> <input type="radio" id="rd2" onchange="f1()" name="search" > By Language</label>';
block.appendChild(p1);
block.appendChild(p2);
let p3 = document.createElement('div');
p3.className='bottom';
p3.innerHTML=' <p>Please choose search query <select id="select" ></select></p>';
appRoot.appendChild(h1);
appRoot.appendChild(block);
appRoot.appendChild(p3);
function forEch(array){
let select =document.getElementById('select');
for (let i = 0; i < array.length; i++) {
let el = document.createElement("option"),
txt = document.createTextNode(array[i]);
el.appendChild(txt);
select.insertBefore(el, select.lastChild)
}
}
function f1(){
let a=document.getElementById('rd1');
let b=document.getElementById('rd2');
if (a.checked===true){
forEch(externalService.getRegionsList());
}else if(b.checked===true) {
forEch(externalService.getLanguagesList());
}
}
[1]: https://i.stack.imgur.com/43PUn.png
p2.className='btn-group2';
p2.innerHTML='按区域'+
“按语言”;
块。子块(p1);
块。子块(p2);
设p3=document.createElement('div');
p3.className='bottom';
p3.innerHTML='请选择搜索查询';
批准附件(h1);
批准附件(块);
批准附件(p3);
函数预测(数组){
让select=document.getElementById('select');
for(设i=0;i