HTMLonchangeイベント属性

❮HTMLイベント属性

ユーザーが<select>要素の選択されたオプションを変更したときにJavaScriptを実行します。

<select onchange="myFunction()">

以下の「自分で試してみてください」の例をもっと見てください。


定義と使用法

onchange属性は、要素の値が変更された瞬間に起動します。

ヒント:このイベントは、 oninputイベントに似ています。違いは、oninputイベントは要素の値が変更された直後に発生するのに対し、onchangeは要素がフォーカスを失ったときに発生することです。もう1つの違いは、onchangeイベントが<select>要素でも機能することです。


ブラウザのサポート

Event Attribute
onchange Yes Yes Yes Yes Yes

構文

<element onchange="script">

属性値

Value Description
script The script to be run on onchange

技術的な詳細

サポートされているHTMLタグ: <input type = "checkbox">、<input type = "file">、<input type = "password">、<input type = "radio">、<input type = "range">、<input type = " search ">、<input type =" text ">、<select>、<textarea>

その他の例

ユーザーが入力フィールドの内容を変更したときにJavaScriptを実行します。

<input type="text" name="txt" value="Hello" onchange="myFunction(this.value)">

関連ページ

HTML DOMリファレンス:onchangeイベント


❮HTMLイベント属性