Home  >  Article  >  Web Front-end  >  Native js realizes the acquisition of shift/ctrl/alt keys_javascript skills

Native js realizes the acquisition of shift/ctrl/alt keys_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:37:511529browse
Copy code The code is as follows:

document.onclick = function(e){
alert(getKey (e));
};
function getKey(e){
var e = e || window.event;
var keys = [];

if(e .shiftKey){
keys.push("shift key");
};
if(e.ctrlKey){
keys.push("ctrl key");
};
if(e.altKey){
keys.push("alt key");
};
return keys;
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn