我有一个textarea
,其中当您单独按Enter时会触发一个jquery ajax,但我想添加的功能是当您按Enter + Shift时仅转到新行而不触发阿贾克斯。你能指导我吗?
这是到目前为止我在jquery中编写的代码,但是当我单击Shift + Enter时,也会触发ajax,我需要消除它
$('.inbox_message_textarea').keydown(function(e) {
var code = e.keyCode || e.which;
if(code == 13) { //Enter keycode
console.log("You pressed Enter Key alone");
}
if( code == 13 && e.shiftKey ) {
e.preventDefault();
console.log("You pressed SHIFT+ENTER");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="inbox_message_textarea"></textarea>
答案 0 :(得分:1)
首先检查 Shift + Enter 按下,然后选中 Enter 按下。同时使用<ng-select
[items]="people$3 | async"
bindLabel="name"
[multiple]="true"
[disabled]="disable"
[(ngModel)]="selectedPeople3">
</ng-select>
而不是第二else if
if
$('.inbox_message_textarea').keydown(function(e) {
var code = e.keyCode || e.which;
if (code == 13 && e.shiftKey) {
e.preventDefault();
console.log("You pressed SHIFT+ENTER");
} else if (code == 13) {
console.log("You pressed Enter Key alone");
}
});