Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

javascript - 使用jQuery的escape key的哪个键代码(Which keycode for escape key with jQuery)

I have two functions.(我有两个功能。)

When enter is pressed the functions runs correctly but when escape is pressed it doesn't.(当按下enter时,功能正常运行,但是当按下escape时它不会。) What's the correct number for the escape key?(转义键的正确数字是多少?) $(document).keypress(function(e) { if (e.which == 13) $('.save').click(); // enter (works as expected) if (e.which == 27) $('.cancel').click(); // esc (does not work) });   ask by Shishant translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try with the keyup event :(尝试使用keyup事件 :)

$(document).keyup(function(e) { if (e.keyCode === 13) $('.save').click(); // enter if (e.keyCode === 27) $('.cancel').click(); // esc });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...