Xhtml 简明教程

XHTML - Events

当用户访问某个网站时,他们会做一些事情,比如点击文本、图像和超链接,浮动在某个东西上面等等。这些是 JavaScript 中事件的示例。

When users visit a website, they do things such as click on text, images and hyperlinks, hover-over things, etc. These are examples of what JavaScript calls events.

我们可以在 JavaScript 或 VBScript 中编写我们的事件处理程序,并且可以将这些事件处理程序指定为事件标记属性的值。XHTML 1.0 有一组类似的事件,这些事件在 HTML 4.01 规范中有提供。

We can write our event handlers in JavaScript or VBScript and can specify these event handlers as a value of event tag attribute. The XHTML 1.0 has a similar set of events which is available in HTML 4.01 specification.

The <body> and <frameset> Level Events

只有两个属性可用在文件级别任何事件发生时触发任何 JavaScript 或 VBScript 代码。

There are only two attributes which can be used to trigger any JavaScript or VBScript code, when any event occurs at document level.

Attribute

Value

Description

onload

Script

Script runs when a XHTML document loads.

onunload

Script

Script runs when a XHTML document unloads.

Note − 在这里,脚本是指 VBScript 或 JavaScript 的任何函数或代码片段。

Note − Here, the script refers to any function or piece of code of VBScript or JavaScript.

The <form> Level Events

有以下六个属性可用在表单级别任何事件发生时触发任何 JavaScript 或 VBScript 代码。

There are following six attributes which can be used to trigger any JavaScript or VBScript code when any event occurs at form level.

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.

Keyboard Events

以下三个事件是由键盘生成的。这些事件在 base、bdo、br、frame、frameset、head、html、iframe、meta、param、script、style 和 title 元素中是无效的。

The following three events are generated by keyboard. These events are not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

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.

Other Events

当鼠标与任意 HTML 标签接触时,将生成以下七个事件。这些事件在 base、bdo、br、frame、frameset、head、html、iframe、meta、param、script、style 和 title 元素中无效。

The following seven events are generated by mouse when it comes in contact with any HTML tag. These events are not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

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.