Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. Web API
  3. HTMLInputElement
  4. select

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

HTMLInputElement: select イベント

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.

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

構文

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

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

イベント型

一般的なEvent です。

選択範囲をログ出力

html
<input value="この要素のテキストの一部を選択してみてください。" /><p></p>
js
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 プロパティで設定することもできます。

js
input.onselect = logSelection;

仕様書

Specification
HTML
# event-select
HTML
# handler-onselect

ブラウザーの互換性

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp