我正在尝试将选项字段添加到选择字段,所有这些都在同一JavaScript中,如下所示:
function addRow() {
var teeArray = JSON.parse(sessionStorage.getItem("teeBoxes"));
var table = document.createElement('tr');
table.innerHTML = '<tr>\
<td>\
<select class="form-control" id="exampleFormControlSelect1">';
for(var i = 0; i < teeArray.length; i++){
table.innerHTML += '<option value="foo">Foo '+i+'</option>';
}
table.innerHTML += '</select>\
</td>\
<td><input id="p1" name="p1" type="number" placeholder="" class="form-control input-md wField"></td>\
<td><input id="p2" name="p2" type="number" placeholder="" class="form-control input-md wField"></td>\
<td><input id="p3" name="p3" type="number" placeholder="" class="form-control input-md mField"></td>\
<td><input id="p4" name="p4" type="number" placeholder="" class="form-control input-md mField"></td>\
</tr>';
document.getElementById('teeBody').appendChild(table);
}
这不是我想的那样...所有选项字段都添加在<select></select>
标记之外。
我如何做到这一点?