fapchat
@fapchat

Зачем в new Option третий параметр?

на что оно влияет?

<!doctype html>
<body>
<select id="genres">
  <option value="rock">Rock</option>
  <option value="blues" selected>Blues</option>
</select>

<script>
  // 1)
  let selectedOption = genres.options[genres.selectedIndex];


  // 2)
  let newOption = new Option("Classic", "classic", true, true);
  genres.append(newOption);

  // 3)
</script>
</body>


Объяните на этом примере, ли на другом, в документации вообще не понятно как это на практике отражается
  • Вопрос задан
  • 321 просмотр
Пригласить эксперта
Ответы на вопрос 1
Stalker_RED
@Stalker_RED
defaultSelected Optional
A Boolean that sets the selected attribute value, i.e. so that this will be the default value selected in the element when the page is first loaded. If this is not specified, a default value of false is used. Note that a value of true does not set the option to selected if it is not already selected.

https://developer.mozilla.org/en-US/docs/Web/API/H...
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы