【发布时间】:2013-03-05 18:27:56
【问题描述】:
以下代码在 IE 和 Chrome(最新版本)中正常工作
$('#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();
};
});
上面的代码执行“区分大小写的实时搜索”,并且无法执行在 Firefox 中捕获退格键的代码块:
// capture backspace
if (event.keyCode == 8) {
// show item that contains searchTxt
$('.item:contains(' + searchTxt + ')').show();
};
【问题讨论】:
标签: jquery events firefox live keycode