Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at https://viewsourceconf.org

event.type

概述

返回一个字符串, 表示该事件对象的事件类型.

传给 EventTarget.addEventListener()EventTarget.removeEventListener() 方法的 event 参数的值是忽略大小写的.

要了解所有的事件类型, 请查看 Mozilla 事件类型参考.

语法

event.type

示例

var string = event.type;
<!DOCTYPE html>
<html lang="en">
<head>

<title>type example</title>

<script>
var currEvent = null;

function getEvtType(evt) {
  currEvent = evt.type;
  document.getElementById("Etype").firstChild.nodeValue = currEvent;
}

</script>
</head>

<body
  onkeydown="getEvtType(event)"
  onkeyup="getEvtType(event)"
  onmousedown="getEvtType(event)"
  onmouseup="getEvtType(event)">

<p>Press any key or click the mouse to get the event type.</p>
<p>Event type: <span id="Etype">-</span></p>

</body>
</html>

规范

文档标签和贡献者

 此页面的贡献者: teoli, ziyunfei
 最后编辑者: teoli,