1) 使用 Option 构造函数和 add() 方法
2) 使用 DOM 方法
let newOption = new Option('Option Text','Option Value'); const select = document.querySelector('select'); select.add(newOption,undefined);
// 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);
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3