
有两种动态创建选项的方法:
1) 使用 option 构造函数和 add() 方法
2) 使用 dom 方法
一个在线商店和CGI脚本的创建工具,帮助您在 Web 上创建和使用多目录的销售商品或服务项目,可以建立和维护购物手推车和Perl CGI 脚本,也提供订单跟踪,管理选项和动态的商品目录
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);









