如何检测在 keyup 上触发了第二次输入?

How to detect second enter is being triggered on keyup?

我需要在按下第一个输入后检测第二个输入。 案例:我有一个输入表单,第一次输入是select一个城市,第二次输入是触发提交。有什么办法吗?

$("#this_is_the_input").keyup(function(e) {
    if (e.keyCode == 13) {
        This is the first enter to select the city. 
        How do I detect the second enter to submit?
    }
});

像这样的东西应该适合你。 clicks 变量跟踪发生了多少个 keyup 事件。希望你有正确的keyCode。如果是第二个,则它会调用第二个警报。如果这不是您需要的,请告诉我。

var clicks=0;
$("#this_is_the_input").keyup(function(e) {
        console.log("clicks: "+clicks);
    if(e.keyCode == 13 )
            clicks++;
    if (e.keyCode == 13 && clicks == 1) {
      console.log("first click");

    }
  else if(e.keyCode == 13 && clicks == 2){
    console.log("second click");
    }
});

试试这个:

count = 0
$("#this_is_the_input").keyup(function(e) {
    if (e.keyCode == 13) {
       if(count == 0)
       {
            //This is the first enter to select the city. 
       }else
       {
            //This is the second enter to submit.
       } 
    count++;
    }
});