A RetroSearch Logo

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

Search Query:

Showing content from http://developer.mozilla.org/ja/docs/Web/API/HTMLInputElement/select_event below:

HTMLInputElement: select イベント - Web API

HTMLInputElement: select イベント

Baseline Widely available

select イベントは、いくらかのテキストが選択されたときに発生します。

構文

このイベント名を addEventListener() 等のメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

addEventListener("select", (event) => {});

onselect = (event) => {};
イベント型

一般的な Event です。

例 選択範囲をログ出力
<input value="この要素のテキストの一部を選択してみてください。" />
<p id="log"></p>
function logSelection(event) {
  const log = document.getElementById("log");
  const selection = event.target.value.substring(
    event.target.selectionStart,
    event.target.selectionEnd,
  );
  log.textContent = `You selected: ${selection}`;
}

const input = document.querySelector("input");
input.addEventListener("select", logSelection);
onselect による同等の処理

イベントハンドラーを onselect プロパティで設定することもできます。

input.onselect = logSelection;
仕様書 ブラウザーの互換性

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