<!DOCTYPE HTML>
<html>
<body>
<select id="genres">
<option value="rock">Rock</option>
<option value="blues" selected>Blues</option>
</select>
<script>
let selectedOption = genres.options[genres.selectedIndex];
alert(selectedOption.value);
let newOption = new Option("Classic", "classic");
genres.append(newOption);
newOption.selected = true;
</script>
</body>
</html>
<html>
<body>
<select id="genres">
<option value="rock">Rock</option>
<option value="blues" selected>Blues</option>
</select>
<script>
let selectedOption = genres.options[genres.selectedIndex];
alert(selectedOption.value);
let newOption = new Option("Classic", "classic");
genres.append(newOption);
newOption.selected = true;
</script>
</body>
</html>
댓글
댓글 쓰기