Event()

Event() 构造函数, 创建一个新的事件对象 Event

语法

 event = new Event(typeArg, eventInit);

参数

typeArg
DOMString 类型,表示所创建事件的名称。
eventInit可选
EventInit 类型的字典,接受以下字段:
  • "bubbles",可选,Boolean类型,默认值为 false,表示该事件是否冒泡。
  • "cancelable",可选,Boolean类型,默认值为 false, 表示该事件能否被取消。
  • "composed",可选,Boolean类型,默认值为 false,指示事件是否会在影子DOM根节点之外触发侦听器。

示例

// 创建一个支持冒泡且不能被取消的look事件

var ev = new Event("look", {"bubbles":true, "cancelable":false});
document.dispatchEvent(ev);

// 事件可以在任何元素触发,不仅仅是document
myDiv.dispatchEvent(ev);

规范

Specification Status Comment
DOM
Event()
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Event() constructorChrome Full support 15Edge Full support YesFirefox Full support 11IE No support NoOpera Full support 11.6Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 14Opera Android Full support 12Safari iOS Full support 6Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

相关阅读