问题描述
我正在尝试创建一个动态选项列表,我有一个包含我想要的数据的数组。我的想法是做一个 for,给它数组的长度并在里面创建选项,但这样做时它对我不起作用,它只会创建一个选项。
addEventListener('load',inicio,false);
function inicio(){
var dato = document.getElementById("dato1").value;
var boton = document.getElementById("b_enviar");
var b_a = document.getElementById("b_crear");
var datos = new Array();
boton.addEventListener('click',function(){
datos.push(document.getElementById("dato1").value);
console.log(datos);
},false);
b_crear.addEventListener('click',function(){
var section1 = document.getElementById('section1');
var section2 = document.getElementById('section2');
var select = document.createElement('select');
var option = document.createElement('option');
var s1 = section1.appendChild(select);
for (let index = 0; index < datos.length; index++) {
s1.appendChild(option);
console.log(index);
}
},false);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)