我有一个文本区域字段,当用户按回车键时提交信息。以下是我所拥有的:
$(document)ready(function(){
$('textarea').on('keypress',function(e){
var txt;
txt = $(this).val();
if(e.which == 13)
{
//submit the form
}
});
});
我想做的是当用户仅按回车键时提交信息,并在用户按住控制键并按回车键时执行硬返回。 (上面的代码工作正常)我只是不知道如何为按住选项添加其他代码。请解释一下答案。
最佳答案
您可以使用e.ctrlKey
:
$(document).ready(function(){
$('textarea').on('keypress',function(e) {
var txt=$(this).val();
if(e.which === 13 || e.which === 10) {
if (e.ctrlKey) {
// handle ctrl-ret here
} else {
//submit the form
}
}
});
});
关于javascript - jquery中的多按键功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16227460/