我正在使用以下代码创建新的下拉列表。该名称由页面上的多个下拉列表使用。
var cellSel = row.insertCell(1);
var sel1 = document.createElement('select');
sel1.name = 'list[]';
sel1.options[0] = new Option('1', '1');
sel1.options[1] = new Option('2', '2');
sel1.options[2] = new Option('3', '3');
sel1.options[3] = new Option('4', '4');
cellSel.appendChild(sel1);
创建后,我希望将选项3设置为选定的条目,我该怎么做?
感谢
sel1.options [3] .selected = true
var cellSel = row.insertCell(1);
var sel1 = document.createElement('select');
sel1.name = 'list[]';
sel1.options[0] = new Option('1', '1');
sel1.options[1] = new Option('2', '2');
sel1.options[2] = new Option('3', '3', true);
sel1.options[3] = new Option('4', '4');
cellSel.appendChild(sel1);