LoginSignup
0
0

More than 5 years have passed since last update.

使用dispatchEvent

Posted at

对于使用document.addEventListener方法绑定的事件,需要使用dispatchEvent来手动触发事件

onchange事件的例子


if ("createEvent" in document) {
  var evt = document.createEvent("HTMLEvents");
  evt.initEvent("change", true, true);
  theElement.dispatchEvent(evt);
} else {
  theElement.fireEvent("onchange");
}


demo

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0