ygunoil

回车键 keyCode 13

HTMLElement.prototype.pressKey = function(code) {
var evt = document.createEvent("UIEvents");
evt.keyCode = code;
evt.initEvent("keydown", true, true);
this.dispatchEvent(evt);
}

  

test:

document.body.onkeydown = function(e) {
    console.log("key pressed, code=" + e.keyCode);
};

document.body.pressKey(13);

  


 eventType 的合法值和每个值创建的事件接口:

参数 事件接口 初始化方法
HTMLEvents HTMLEvent iniEvent()
MouseEvents MouseEvent iniMouseEvent()
UIEvents UIEvent iniUIEvent()
参照文档:

http://www.w3school.com.cn/xmldom/met_document_createevent.asp

http://www.w3school.com.cn/xmldom/dom_event.asp
————————————————
版权声明:本文为CSDN博主「fareast_mzh」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/fareast_mzh/article/details/83416064

分类:

技术点:

相关文章:

  • 2021-08-13
  • 2021-08-14
  • 2021-11-27
  • 2021-10-17
  • 2021-11-30
  • 2021-11-06
  • 2021-11-09
猜你喜欢
  • 2021-08-23
  • 2021-08-02
  • 2021-09-07
  • 2021-09-07
  • 2021-11-04
  • 2021-08-23
  • 2021-09-10
相关资源
相似解决方案