A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/ja/docs/Web/API/HTMLSelectElement/selectedIndex below:

HTMLSelectElement: selectedIndex プãƒãƒ‘ティ - Web API

HTMLSelectElement: selectedIndex プロパティ

Baseline Widely available

HTMLSelectElement.selectedIndex は long 値であり、選択されている <option> 要素のうち、multiple の値に応じて最初または最後のものを返します。-1 の値は選択されている要素がないことを示します。

値

数値です。

例 HTML
<p id="p">selectedIndex: 0</p>

<select id="select">
  <option selected>Option A</option>
  <option>Option B</option>
  <option>Option C</option>
  <option>Option D</option>
  <option>Option E</option>
</select>
JavaScript
const selectElem = document.getElementById("select");
const pElem = document.getElementById("p");

// When a new <option> is selected
selectElem.addEventListener("change", () => {
  const index = selectElem.selectedIndex;
  // Add that data to the <p>
  pElem.textContent = `selectedIndex: ${index}`;
});
結果 仕様書 ブラウザーの互換性

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4