【发布时间】:2012-02-11 12:45:11
【问题描述】:
我正在尝试对我的移动网站进行实时搜索,我不想每次用户输入字母时都查询数据库,所以我创建了一个有序列表,其中包含所有可以搜索的名称,我我用 jquery 遍历它,问题是我有 3300 个名字,当它搜索它们时它会冻结浏览器,谁能给我一个关于更好方法的提示?这是我的代码:
$(document).ready(function(){
$("input#search").keyup(function(){
var filter = $(this).val(), count = 0;
var html = "";
$("ol.pacientes li").each(function(){
var nome_paciente = $(this).text();
if(nome_paciente.indexOf(filter.toUpperCase()) != -1){
html = html + " " + nome_paciente;
}
$('#pacientes_hint').html(html);
});
【问题讨论】:
标签: javascript jquery search live