2011-01-19 74 views
0

這很奇怪,但我有一些自定義代碼,只有當您鍵入'@'符號時才進行自定義代碼...在FireFox中,它非常棒。我輸入一個'@',然後出現下拉菜單。Chrome和jQuery問題

但是......當我在Chrome中嘗試它時,它需要兩個'@@'來使用下拉菜單。

這可能是什麼?

這裏是激活自動完成下拉switch語句代碼:

  case KEY.ATSIGN: 
      clearTimeout(timeout); 
      timeout = setTimeout(onChange, options.delay); 
      //alert("hi"); 
      //select.show(); 
      break; 
     default: 

      break; 

另一個奇怪的現象是,當廣告警報statment,它實際上當我輸入在Chrome一個「@」工程.. 。 有想法該怎麼解決這個嗎?謝謝!

編輯

這裏就是我與空白「時,從下拉列表中選擇一個項目替換爲@符號」,所以它不顯示或提交@中的onChange功能

function onChange(crap, skipPrevCheck) { 
    if(lastKeyPressCode == KEY.DEL) { 
     select.hide(); 
     return; 
    } 

    var currentValue = $input.val(); 

    if (!skipPrevCheck && currentValue == previousValue) 
     return; 

    previousValue = currentValue; 

    currentValue = lastWord(currentValue); 
    if (currentValue.length >= options.minChars) { 
     $input.addClass(options.loadingClass); 
     if (!options.matchCase) 
      currentValue = currentValue.toLowerCase(); 
      currentValue = currentValue.replace("@",""); 
      request(currentValue, receiveData, hideResultsNow); 
      //alert(currentValue); 
    } else { 
     stopLoading(); 
     select.hide(); 
    } 
}; 

NEW編輯 你可以看到在符號ASCII值在這裏設置爲50

var KEY = { 
    UP: 38, 
    DOWN: 40, 
    DEL: 46, 
    TAB: 9, 
    RETURN: 13, 
    ESC: 27, 
    COMMA: 188, 
    PAGEUP: 33, 
    PAGEDOWN: 34, 
    BACKSPACE: 8, 
    ATSIGN: 50 
}; 
switch語句

然後,自動完成只得到激活時, @符號被壓:

 switch(event.keyCode) { 

     case KEY.UP: 
      event.preventDefault(); 
      if (select.visible()) { 
       select.prev(); 
      } else { 
       onChange(0, true); 
      } 
      break; 

     case KEY.DOWN: 
      event.preventDefault(); 
      if (select.visible()) { 
       select.next(); 
      } else { 
       onChange(0, true); 
      } 
      break; 

     case KEY.PAGEUP: 
      event.preventDefault(); 
      if (select.visible()) { 
       select.pageUp(); 
      } else { 
       onChange(0, true); 
      } 
      break; 

     case KEY.PAGEDOWN: 
      event.preventDefault(); 
      if (select.visible()) { 
       select.pageDown(); 
      } else { 
       onChange(0, true); 
      } 
      break; 

     // matches also semicolon 
     case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA: 
     case KEY.TAB: 
     case KEY.RETURN: 
      if(selectCurrent()) { 
       // stop default to prevent a form submit, Opera needs special handling 
       event.preventDefault(); 
       blockSubmit = true; 
       return false; 
      } 
      break; 

     case KEY.ESC: 
      select.hide(); 
      break; 
     case KEY.ATSIGN: 
      clearTimeout(timeout); 
      timeout = setTimeout(onChange, options.delay); 
      //alert("hi"); 
      //select.show(); 
      break; 
     default: 

      break; 
    } 

這裏是函數的onChange @按下

function onChange(crap, skipPrevCheck) { 
    if(lastKeyPressCode == KEY.DEL) { 
     select.hide(); 
     return; 
    } 

    var currentValue = $input.val(); 

    if (!skipPrevCheck && currentValue == previousValue) 
     return; 

    previousValue = currentValue; 
    //alert(previousValue); 
    currentValue = lastWord(currentValue); 
    if (currentValue.length >= options.minChars) { 
     $input.addClass(options.loadingClass); 
     if (!options.matchCase) 
      currentValue = currentValue.toLowerCase(); 
      currentValue = currentValue.replace("@",""); 
      //alert(currentValue); 
      request(currentValue, receiveData, hideResultsNow); 

    } else { 
     stopLoading(); 
     select.hide(); 
    } 
}; 

後,正如我提到,被調用的情況下發言,這在FF的偉大工程......我按@一次自動完成激活。不過在Chrome中,我必須按@@(at符號兩次)....

而且,這裏是一段代碼的switch語句

// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all 
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) { 
    // a keypress means the input has focus 
    // avoids issue where input had focus before the autocomplete was applied 
    hasFocus = 1; 
    // track last key pressed 
    lastKeyPressCode = event.keyCode; 
前右
+0

要哪個事件是「活化劑」耦合來模仿一個簡單的例子?的onkeyup? – Gidon 2011-01-19 09:23:18

+0

我想你已經成功向我們展示了兩段與問題無關的代碼。 :) – galambalazs 2011-01-19 09:27:46

回答