HTML onkeyup イベント属性

❮ HTML イベント属性

ユーザがキー離したときに JavaScript を実行します:

<input type="text" onkeyup="myFunction()">
Try it Yourself ❯

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


定義と用法

onkeyup 属性は、ユーザが(キーボードの)キー離したときに発火します。

チップ: onkeyup イベントに関連するイベントの順序:

  1. onkeydown
  2. onkeypress
  3. onkeyup

ブラウザ・サポート

イベント属性
onkeyup Yes Yes Yes Yes Yes

HTML 4.01 と HTML5 の相違点

なし。


構文

<element onkeyup="script">

属性値

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

技術的詳細

サポートする HTML タグ: 次の要素を除くすべての HTML 要素: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

Examples

その他の例

"onkeyup" 属性と一緒に "onkeydown" を使用します: Using "onkeydown" together with the "onkeyup" attribute:

<input type="text" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
Try it Yourself ❯

テキストフィールド内で離した実際のキーを出力します:

Enter your name: <input type="text" id="fname" onkeyup="myFunction()">

<script>
function myFunction() {
    var x = document.getElementById("fname").value;
    document.getElementById("demo").innerHTML = x;
}
</script>
Try it Yourself ❯

関連ページ

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


HTML Event Attributes HTML イベント属性