手动触发事件

2018-11-26  本文已影响0人  忍不住的k
可通过原生方法调用的事件:
DOM原生可以手动触发的事件
document.createElement('input').click
ƒ click() { [native code] }
document.createElement('input').focus
ƒ focus() { [native code] }
document.createElement('input').blur
ƒ blur() { [native code] }
document.createElement('input').scroll
ƒ scroll() { [native code] }
document.createElement('input').select
ƒ select() { [native code] }

无法用原生方法分发的事件,可以通过 target.dispatchEvent 方法分发

使用方法如下:

target.dispatchEvent(new MouseEvent('mousedown'));

####### 参考: 自定义事件——Event和CustomEvent

上一篇 下一篇

猜你喜欢

热点阅读