type
只读特性在
事件
interface returns a string containing the event's type. It is set when the event is constructed and is the name commonly used to refer to the specific event, such as
click
,
load
,或
error
.
For a list of available event types, see the event reference .
let eventType = event.type;
A
DOMString
containing the type of
事件
.
This example logs the event type whenever you press a keyboard key or click a mouse button.
<p>Press any key or click the mouse to get the event type.</p> <p id="log"></p>
function getEventType(event) {
const log = document.getElementById('log');
log.innerText = event.type + '\n' + log.innerText;
}
// Keyboard events
document.addEventListener('keydown', getEventType, false); // first
document.addEventListener('keypress', getEventType, false); // second
document.addEventListener('keyup', getEventType, false); // third
// Mouse events
document.addEventListener('mousedown', getEventType, false); // first
document.addEventListener('mouseup', getEventType, false); // second
document.addEventListener('click', getEventType, false); // third
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'Event.type' in that specification. |
实时标准 | |
|
DOM (文档对象模型) 2 级事件规范
The definition of 'Event.type' in that specification. |
过时 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
type
|
Chrome 1 | Edge 12 | Firefox 1 | IE 9 | Opera 7 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 |
完整支持