From bb5e9e9457aaec912bb1d3672e8a925643d4f6d9 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sun, 6 Feb 2022 16:44:19 +0900 Subject: 2021/09/15 時点の英語版に同期 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/api/htmlinputelement/search_event/index.md | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 files/ja/web/api/htmlinputelement/search_event/index.md (limited to 'files/ja') diff --git a/files/ja/web/api/htmlinputelement/search_event/index.md b/files/ja/web/api/htmlinputelement/search_event/index.md new file mode 100644 index 0000000000..21730a1438 --- /dev/null +++ b/files/ja/web/api/htmlinputelement/search_event/index.md @@ -0,0 +1,74 @@ +--- +title: 'HTMLInputElement: search イベント' +slug: Web/API/HTMLInputElement/search_event +tags: + - API + - Event + - HTMLInputElement + - 標準外 + - リファレンス + - Search + - ウェブ +browser-compat: api.HTMLInputElement.search_event +translation_of: Web/API/HTMLInputElement/search_event +--- +{{APIRef}}{{non-standard_header}} + +**`search`** イベントは、 {{HTMLElement("input")}} 要素の `type="search"` にて検索が開始されたときに発生します。 + + + + + + + + + + + + + + + + + + + + +
バブリングはい
キャンセル不可
インターフェイス{{domxref("Event")}}
イベントハンドラープロパティ + onsearch +
+ +検索を開始する方法はいくつかあり、例えば、 {{HTMLElement("input")}} にフォーカスがある時に Enter を押したり、[`incremental`](/ja/docs/Web/HTML/Element/input#attr-incremental) 属性が存在すれば、最も新しいキー入力から UA 定義のタイムアウト時間が経過してから検索が開始されます(新しくキー入力をするとタイムアウトがリセットされるので、イベントが繰り返して発生します)。 + +現在 UA が `` を実装している方法では、フィールド内をクリアするために追加のコントロールを置きます。このコントロールを使用しても `search` イベントが発生します。この場合、 {{HTMLElement("input")}} 要素の `value` は空文字列になります。 + +## 例 + +```js +// addEventListener 版 +const input = document.querySelector('input[type="search"]'); + +input.addEventListener('search', () => { + console.log("The term searched for was " + input.value); +}) + +// onsearch 版 +const input = document.querySelector('input[type="search"]'); + +input.onsearch = () => { + console.log("The term searched for was " + input.value); +}) +``` + +## 仕様書 + +このイベントは仕様書に含まれていません。 + +## ブラウザーの互換性 + +{{Compat}} -- cgit v1.2.3-54-g00ecf