Select lengthProperty

Select 对象参考手册Select Object

Definition and Usage

The length property returns the number of options in a drop-down list.

Syntax

selectObject.length=number


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the length property.


Examples

Examples

Display the number of options in the drop-down list:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
    alert(document.getElementById("mySelect").length);
}
</script>
</head>
<body>

<form>
<select id="mySelect">
  <option>Apple</option>
  <option>Pear</option>
  <option>Banana</option>
  <option>Orange</option>
</select>
</form>
<button type="button" onclick="displayResult()">How many options are in the drop-down list?</button>

</body>
</html>

Try it Yourself »


Select 对象参考手册Select Object Other Extensions