按 Ctrl+c 键自动加载 [英] Press Ctrl+c keys automatically onload
本文介绍了按 Ctrl+c 键自动加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一名新生,在 Coupons 网站上工作.
I am a fresher and working on a Coupons website.
我想知道,当窗口加载时,如何按 ctrl+c 本身.
I want to know, when a window loads, how to press ctrl+c itself.
Ctrl+c 键应在窗口加载后立即自动按下.
推荐答案
由于您使用的是 jQuery,您可以使用 jQuery.Event
:
Since you're using jQuery you could do it using jQuery.Event
:
var e = jQuery.Event("keydown");
e.which = 67; // 'C' key code value
e.ctrlKey = true;
$("body").trigger(e);
希望这会有所帮助.
$(function(){ //Ready function
//Event that catch the Ctrl+C press (Just for test)
$("body").keydown(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 67) {
if (e.ctrlKey) {
alert("Ctrl+C was pressed!!");
}
}
});
//Event that trigger the 'Ctrl+C'
var e = jQuery.Event("keydown");
e.which = 67; // 'C' key code value
e.ctrlKey = true;
$("body").trigger(e);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
这篇关于按 Ctrl+c 键自动加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文