按下箭头然后输入后如何执行功能?

时间:2016-02-26 17:24:57

标签: jquery

我需要在用户首次按下箭头时执行一个功能(以确保用户下降到ui-autocomplete)然后输入。有什么建议?这是我目前的代码:

 Traceback (most recent call last):
      File "preproc.py", line 89, in <module>
        apos=stem_data(nostop)
      File "preproc.py", line 51, in stem_data
        r=stemmer.stem(n)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/stem/porter.py", line 632, in stem
        stem = self.stem_word(word.lower(), 0, len(word) - 1)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/stem/porter.py", line 590, in stem_word
        word = self._step1ab(word)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/stem/porter.py", line 275, in _step1ab
        if word.endswith("sses"):
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 6: ordinal not in range(128)

1 个答案:

答案 0 :(得分:0)

如果您只是需要在downArrowKey键之前截取enter,则可以将符合条件的downArrowKey条件保存到global变量,并检查它&#39; s值和enter键。

var count = 0;
var downArrowPressed = false;
$('#this_is_input').keyup(function(e) {
   if(e.keyCode != 13) {
   downArrowPressed = e.keyCode == 40 ? true : false; }
   console.log(downArrowPressed);
      //  downArrowPressed = true;
    // I need to make sure the user hit arrow down before executing the $('.submitBtn').click();
    if (e.keyCode == 13 && downArrowPressed) {
        // First enter pressed
        if(count == 0) 
        { 
            downArrowPressed = false;
            alert('Submit');
           // $('.submitBtn').click();
           // CONFIRM_LOCATION.attr('disabled', 'disabled');
        }
     //   count++;
    }
});

示例:https://jsfiddle.net/DinoMyte/up4j39qr/9/