Xhtml-events
提供:Dev Guides
XHTML-イベント
ユーザーがWebサイトにアクセスすると、テキスト、画像、ハイパーリンクのクリック、ホバーオーバーなどの操作を行います。 これらはJavaScriptがイベントと呼ぶものの例です。
JavaScriptまたはVBScriptでイベントハンドラを記述し、これらのイベントハンドラをイベントタグ属性の値として指定できます。 XHTML 1.0には、HTML 4.01仕様で利用可能な同様のイベントセットがあります。
<body>および<frameset>レベルのイベント
ドキュメントレベルでイベントが発生したときにJavaScriptまたはVBScriptコードをトリガーするために使用できる属性は2つだけです。
| Attribute | Value | Description |
|---|---|---|
| onload | Script | Script runs when a XHTML document loads. |
| onunload | Script | Script runs when a XHTML document unloads. |
注-ここで、スクリプトとは、VBScriptまたはJavaScriptの任意の関数またはコードを指します。
<form>レベルのイベント
フォームレベルでイベントが発生したときにJavaScriptまたはVBScriptコードをトリガーするために使用できる次の6つの属性があります。
| Attribute | Value | Description |
|---|---|---|
| onchange | Script | Script executes when the element changes. |
| onsubmit | Script | Script executes when the form is submitted. |
| onreset | Script | Script executes when the form is reset. |
| onselect | Script | Script executes when the element is selected. |
| onblur | Script | Script executes when the element loses focus. |
| onfocus | Script | Script runs when the element gets focus. |
キーボードイベント
次の3つのイベントがキーボードによって生成されます。 これらのイベントは、base、bdo、br、frame、frameset、head、html、iframe、meta、param、script、style、およびtitle要素では無効です。
| Attribute | Value | Description |
|---|---|---|
| onkeydown | Script | Script executes on key press. |
| onkeypress | Script | Script executes on key press and release. |
| onkeyup | Script | Script executes key release. |
その他のイベント
マウスがHTMLタグと接触すると、次の7つのイベントがマウスによって生成されます。 これらのイベントは、base、bdo、br、frame、frameset、head、html、iframe、meta、param、script、style、およびtitle要素では無効です。
| Attribute | Value | Description |
|---|---|---|
| onclick | Script | Script executes on a mouse click. |
| ondblclick | Script | Script executes on a mouse double-click. |
| onmousedown | Script | Script executes when mouse button is pressed. |
| onmousemove | Script | Script executes when mouse pointer moves. |
| onmouseout | Script | Script executes when mouse pointer moves out of an element. |
| onmouseover | Script | Script executes when mouse pointer moves over an element. |
| onmouseup | Script | Script executes when mouse button is released. |