HTML onkeydown イベント属性

❮ HTML イベント属性

ユーザがキーを押しているときに JavaScript を実行します:

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

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


定義と用法

onkeydown 属性は、ユーザが(キーボードの)キーを押しているときに発火します。

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

  1. onkeydown
  2. onkeypress
  3. onkeyup

ブラウザ・サポート

イベント属性
onkeydown Yes Yes Yes Yes Yes

HTML 4.01 と HTML5 の相違点

なし。


構文

<element onkeydown="script">

属性値

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

技術的詳細

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

Examples

その他の例

"onkeyup" 属性と一緒に "onkeydown" を使用します:

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

関連ページ

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


HTML Event Attributes HTML イベント属性