aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/htmlselectelement/selectedindex
diff options
context:
space:
mode:
authorMasahiro FUJIMOTO <mfujimot@gmail.com>2021-10-28 02:00:01 +0900
committerMasahiro FUJIMOTO <mfujimot@gmail.com>2021-11-04 21:36:13 +0900
commited4edb19c89e81e9f6e68f6820b166d106519be6 (patch)
treeaaa2ad0f16fad2a547ec5011d5c3e40180555b96 /files/ja/web/api/htmlselectelement/selectedindex
parent485a48198a98d7213af29b946d473c9c3329a6b1 (diff)
downloadtranslated-content-ed4edb19c89e81e9f6e68f6820b166d106519be6.tar.gz
translated-content-ed4edb19c89e81e9f6e68f6820b166d106519be6.tar.bz2
translated-content-ed4edb19c89e81e9f6e68f6820b166d106519be6.zip
Web/API/HTMLSelectElement 以下の文書を更新
- 2021/10/27 時点の英語版に同期 - add, checkValidity, disabled, form, labels, namedItem, remove, selectedIndex, selectedOptions, setCustomValidaty, type については新規翻訳
Diffstat (limited to 'files/ja/web/api/htmlselectelement/selectedindex')
-rw-r--r--files/ja/web/api/htmlselectelement/selectedindex/index.md63
1 files changed, 63 insertions, 0 deletions
diff --git a/files/ja/web/api/htmlselectelement/selectedindex/index.md b/files/ja/web/api/htmlselectelement/selectedindex/index.md
new file mode 100644
index 0000000000..2288f57d2e
--- /dev/null
+++ b/files/ja/web/api/htmlselectelement/selectedindex/index.md
@@ -0,0 +1,63 @@
+---
+title: HTMLSelectElement.selectedIndex
+slug: Web/API/HTMLSelectElement/selectedIndex
+tags:
+ - API
+ - HTML DOM
+ - HTML フォーム
+ - HTMLSelectElement
+ - プロパティ
+ - リファレンス
+browser-compat: api.HTMLSelectElement.selectedIndex
+translation_of: Web/API/HTMLSelectElement/selectedIndex
+---
+{{APIRef("HTML DOM")}}
+
+**`HTMLSelectElement.selectedIndex`** は `long` 値であり、選択されている {{HTMLElement("option")}} 要素のうち、`multiple` の値に応じて最初または最後のものを返します。`-1` の値は選択されている要素がないことを示します。
+
+## 構文
+
+```js
+var index = selectElem.selectedIndex;
+selectElem.selectedIndex = index;
+```
+
+<h2 id="Example">例</h2>
+
+### HTML
+
+```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
+
+```js
+var selectElem = document.getElementById('select')
+var pElem = document.getElementById('p')
+
+// When a new <option> is selected
+selectElem.addEventListener('change', function() {
+ var index = selectElem.selectedIndex;
+ // Add that data to the <p>
+ pElem.innerHTML = 'selectedIndex: ' + index;
+})
+```
+
+{{EmbedLiveSample("Example", "200px", "80px")}}
+
+## 仕様書
+
+{{Specifications}}
+
+## ブラウザーの互換性
+
+{{Compat}}