单击按钮时执行Ctrl + D. [英] Execute Ctrl+D on button click

查看:150
本文介绍了单击按钮时执行Ctrl + D.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模仿按键事件,例如按下按钮时按Ctrl + D.

I am trying to mimic key press events, for instance Ctrl+D on a button click.

如果有人能指出我正确的方向会很棒关于如何实现相同的目标。

It would be great if someone can point me in the right direction on how to achieve the same.

推荐答案

触发自定义事件的代码(在本例中为Ctrl + d)为如下:

The code for triggering a custom event (in this instance, Ctrl+d) is as follows:

var evt = jQuery.Event("keypress");
evt.keyCode = 100; // d
evt.ctrlKey = true;
$(document).trigger(evt);

请注意,正如其他答案所说,这将影响其影响。您将无法以这种方式影响正常的浏览器功能。

NB that, as the other answers have said, this will be limited in its impact. You won't be able to affect normal browser functions in this way.

这篇关于单击按钮时执行Ctrl + D.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆