📜  在javascript代码示例中取消事件

📅  最后修改于: 2022-03-11 15:02:38.432000             🧑  作者: Mango

代码示例1
// call the preventDefault() method on the event
function preventScrollWheel(event) {
  if (typeof event.cancelable !== 'boolean' || event.cancelable) {
    event.preventDefault();
  } else {
    // to call preventDefault() on it.
    console.warn(`The following event couldn't be canceled:`);
    console.dir(event);
  }
}

document.addEventListener('wheel', preventScrollWheel);