使用dropdownlist綁定數據的步驟如下:
<select id="myDropdownList"></select>
var dropdownList = document.getElementById("myDropdownList");
var data = ["選項1", "選項2", "選項3"];
for (var i = 0; i < data.length; i++) {
var option = document.createElement("option");
option.text = data[i];
dropdownList.add(option);
}
完整的示例代碼如下:
<select id="myDropdownList"></select>
<script>
var dropdownList = document.getElementById("myDropdownList");
var data = ["選項1", "選項2", "選項3"];
for (var i = 0; i < data.length; i++) {
var option = document.createElement("option");
option.text = data[i];
dropdownList.add(option);
}
</script>
這樣就完成了使用dropdownlist綁定數據的操作。