HTMLSelectElement: value-Eigenschaft
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Die HTMLSelectElement.value
-Eigenschaft enthält den Wert des ersten ausgewählten <option>
-Elements, das mit diesem <select>
-Element verknüpft ist.
Diese Eigenschaft kann auch direkt gesetzt werden, beispielsweise um einen Standardwert basierend auf einer bestimmten Bedingung festzulegen.
Wert
Beispiele
Den ausgewählten Wert abrufen
html
<label for="bird-select">Choose a bird:</label>
<select name="birds" id="bird-select">
<option value="">--Please choose an option--</option>
<option value="Scarlet ibis">Scarlet ibis</option>
<option value="Marabou stork">Marabou stork</option>
<option value="Roseate spoonbill">Roseate spoonbill</option>
</select>
<pre id="log"></pre>
js
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = text;
}
const select = document.querySelector("#bird-select");
select.addEventListener("change", () => {
log(`Selection: ${select.value}`);
});
Spezifikationen
Specification |
---|
HTML # dom-select-value-dev |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
value |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Siehe auch
- Das
<select>
HTML-Element, welches diese Schnittstelle implementiert.