en.javascript.info/2-ui/4-forms-controls/1-form-elements/1-add-select-option/solution.md
2015-03-12 10:26:02 +03:00

460 B

Решение:

<!--+ run -->
<select>
  <option value="Rock">Рок</option>
  <option value="Blues" selected>Блюз</option>
</select>

<script>
  var select = document.body.children[0];

  // 1) 
  var selectedOption = select.options[select.selectedIndex];
  alert( selectedOption.value );

  // 2)
  var newOption = new Option("Classic", "Классика");
  select.appendChild(newOption);

  // 3)
  newOption.selected = true;
</script>