且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 vanilla javascript 中向现有选择动态添加选项

更新时间:2023-08-17 16:03:46

本教程准确显示了您需要执行的操作:使用javascript向HTML选择框添加选项

This tutorial shows exactly what you need to do: Add options to an HTML select box with javascript

基本上:

 daySelect = document.getElementById('daySelect');
 daySelect.options[daySelect.options.length] = new Option('Text 1', 'Value1');