Event()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Event()
构造函数,创建一个新的事件对象 Event
。
语法
js
new Event(type)
new Event(type, options)
参数
示例
js
// 创建一个支持冒泡且不能被取消的 look 事件
var ev = new Event("look", { bubbles: true, cancelable: false });
document.dispatchEvent(ev);
// 事件可以在任何元素触发,不仅仅是 document
myDiv.dispatchEvent(ev);
规范
Specification |
---|
DOM Standard # ref-for-dom-event-event |
浏览器兼容性
BCD tables only load in the browser