js 主动触发esc

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

          document.body.pressKey(27); // 主动触发esc
发布了55 篇原创文章 · 获赞 12 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/mrzhangdulin/article/details/97111510