2011-01-19 4 views
0

이상한 일이지만 '@'기호를 입력 할 때만 사용하도록 사용자 정의한 자동 완성 코드가 있습니다. FireFox에서는 훌륭하게 작동합니다. '@'을 입력하면 드롭 다운이 나타납니다.크롬 및 jQuery 문제

하지만 Chrome에서 시도 할 때 드롭 다운 메뉴를 사용하려면 '@@'가 두 개 필요합니다.

무엇이 될 수 있습니까? 여기

은 자동 완성 드롭 다운을 활성화 스위치 문에서 코드입니다 :

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

      break; 

또 다른 이상한 행동은 그 나는 하나의 '@'크롬을 입력 할 때 광고가 경고 한 Statment, 그것은 실제로 작동 할 때 .. 이 문제를 해결하는 방법에 대한 아이디어가 있습니까? 감사! 편집

는 여기 표시하거나 @를 제출하지 않도록 항목을 드롭 다운에서 선택했을 때 내가 ""빈에 @ 기호를 교체하고 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 편집 당신은 기호에 아스키 값이 switch 문에서 다음

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

50 여기에 설정되어 볼 수 있습니다, 자동 완성은 경우에만 활성화됩니다 @ 기호를 누르면 :

 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; 
    } 

을 그리고 여기에 내가 언급 한 바와 같이 @가

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(); 
    } 
}; 

을 누른 후 case 문에서 호출되는 함수의 onChange이며,이 나는 ... FF에서 잘 작동합니다 언론 번 @ 및 자동 완성 또한 여기에 .... 내가 (두 번 기호에) @@ 눌러야합니다, 크롬에서 그러나 ...

를 활성화 바로 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; 
01,235,164하기 전에 코드의 비트입니다
+0

같은에서 간단한 예를 조롱 할 수 있습니다? onkeyup? – Gidon

+0

문제와 관련이없는 코드 2 개를 성공적으로 보여준 것 같습니다. :) – galambalazs

+0

액티베이터는 @ 기호를 눌렀을 때 나타납니다 ... Ascii 50. –

답변

0

질문에 대한 3 번째 댓글을보세요.

jQuery Event Keypress: Which key was pressed?

당신의 키를 대신의 keyup 사용하여 시도하고 당신이 얼마나 멀리보고 할 수 있습니다. 또한 문제를 게시하는 경우 모든 비 관련 코드를 제거하고 문제를 최소한으로 줄이는 것이 가장 좋습니다.

당신은 또한 이벤트은 "활성화"가 결합되는 http://jsbin.com/

+0

글쎄 - 당신이이 질문의 사본을 게시 한 다음 당신이 대답을 발견했음을 알았습니다 -이 질문에 대해 똑같이 했어야합니다 - 또는 그것이 닫히도록 요청 ... – calumbrodie