HTML onchange イベント属性

❮ HTML イベント属性

ユーザが、<select>要素の選択した選択肢を変更したときに JavaScript を実行します:

<select onchange="myFunction()">
Try it Yourself ❯

他の "Try it Yourself" の例が下にあります。


定義と用法

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

チップ: このイベントは、oninput イベントに似ています。 違いは、 oninput イベントが要素の値が変更された直後に発生する一方で、onchange は要素がフォーカスを失ったときに発生します。 その他の違いは、onchange イベントは <keygen> および <select> 要素でも動作することです。.


ブラウザ・サポート

イベント属性
onchange Yes Yes Yes Yes Yes

HTML 4.01 と HTML5 の相違点

なし。


構文

<element onchange="script">

属性値

説明
script script は onchange で実行される

技術的詳細

サポートする HTML タグ: <input type="checkbox">, <input type="file">, <input type="password">, <input type="radio">, <input type="range">, <input type="search">, <input type="text">, <keygen>, <select> and <textarea>

Examples

その他の例

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

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

関連ページ

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


HTML Event Attributes HTML イベント属性