드롭다운 목록에서 모든 옵션을 표시하려면 옵션을 사용하십시오. 재산. 속성을 사용하면 length의 모든 옵션을 얻을 수 있습니다. 재산.
예시
다음 코드를 실행하여 드롭다운 목록에서 모든 옵션을 가져올 수 있습니다.
<!DOCTYPE html>
<html>
<body>
<form id="myForm">
<select id="selectNow">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
<input type="button" onclick="display()" value="Click">
</form>
<p>Click the button to get all the options</p>
<script>
function display() {
var a, i, options;
a = document.getElementById("selectNow");
options = "";
for (i = 0; i < a.length; i++) {
options = options + "<br> " + a.options[i].text;
}
document.write("DropDown Options: "+options);
}
</script>
</body>
</html>