2013-03-05 3 views
1

아래 코드는 IE와 크롬에서 제대로 작동 (최신 버전)jQuery - even.keyCode가 Firefox에서 올바르게 인식되지 않습니까?

$('#searchBox').keyup(function() { 
    var searchTxt = $(this).val(); 

    // if item contains searchTxt, 
    if ($('.item:contains("' + searchTxt + '")')) { 
     // hide the items that do NOT contain searchTxt 
     $('.item').not(':contains(' + searchTxt + ')').hide(); 
    }; 

    // capture backspace 
    if (event.keyCode == 8) { 
     // show item that contains searchTxt 
     $('.item:contains(' + searchTxt + ')').show(); 
    }; 

    // if search box is empty, 
    if ($('#searchBox').val() == "") { 
     // show all items 
     $('.item').show(); 
    }; 
}); 

위의 코드는 "대소 문자 구분 라이브 검색"을 수행하고 파이어 폭스에서 백 스페이스 키를 캡처 코드의 덩어리를 실행하는 데 실패

// capture backspace 
if (event.keyCode == 8) { 
    // show item that contains searchTxt 
    $('.item:contains(' + searchTxt + ')').show(); 
}; 

답변

4

는에 event 인수 넣어 :

$('#searchBox').keyup(function (event) { .. })을;

및 대신 keyCode 사용자 event.which.

더 읽기에 대한 event.which

1

이벤트 개체를 선언해야합니다.

$('#searchBox').keyup(function (event) { 
0

과 같은 기능에 이벤트를 전달합니다

$('#searchBox').keyup(function (event) { 

});