如何在两个文本区域中按下回车键时显示 div?

How to show a div when the enter key has been pressed in two textareas?

如何检测两次按下回车键textareas?我有一种方法可以检测一次按下回车键 textarea 并且需要帮助检测两次按下回车键 textareas.

这是我目前所做的:

$('#test1').keyup(function(e) {
   if(e.keyCode == 13) {
        $("#GFG_DOWN").text("Enter key pressed inside textarea");
   }
});  
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea id="test1"></textarea>
        <textarea id="test2"></textarea>
        <br>     
          
        <p id = "GFG_DOWN" style = 
            "color:green; font-size: 20px; font-weight: bold;">
        </p>

我猜你必须用两个 FlagVariables 来处理这个问题。

let text1Flag = false;
let text2Flag = false;

function callbackHandler(e, textType) {
   if(e.keyCode == 13) {
        if (textType == 1) {
            text1Flag = true;
        } else {
            text2Flag = true;
        }
        if (text1Flag && text2Flag) {
           $("#GFG_DOWN").text("Enter key pressed inside textarea");
            text1Flag = false;
            text2Flag = false;
        }
   }
}

$("#test1").keyup((ev) => callbackHandler(ev, 1));
$("#test2").keyup((ev) => callbackHandler(ev, 2));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea id="test1"></textarea>
        <textarea id="test2"></textarea>
        <br>     
          
        <p id = "GFG_DOWN" style = 
            "color:green; font-size: 20px; font-weight: bold;">
        </p>