在我的代码中,我需要在事件分发后与自定义事件进行交互。
// ...
let customEvent = new CustomEvent('myevent', {
bubbles: true,
cancelable: true
});
button.addEventListener('click', function (e) {
e.preventDefault();
otherElement.dispatchEvent( customEvent );
// at this point i neeed some help
// if ( customEvent was canceled or prevented ) { do something }
});
如何检查事件是否被阻止/取消或其他解决方案以获得一些“反馈”?