
有两种动态创建选项的方法:
1) 使用 option 构造函数和 add() 方法
2) 使用 dom 方法
1) 使用 option 构造函数和 add() 方法:
let newoption = new option('option text','option value');
const select = document.queryselector('select');
select.add(newoption,undefined);
2) 使用 dom 方法:
// create option using DOM
const newOption = document.createElement('option');
const optionText = document.createTextNode('Option Text');
// set option text
newOption.appendChild(optionText);
// and option value
newOption.setAttribute('value','Option Value');
const select = document.querySelector('select');
select.appendChild(newOption);










