$( #div_search ).keypress(function() {
var search_term = $(this).val();
$( .ticker_list ).children( div ).each(function() {
var search_value = $(this).attr( search_term );
if (search_value.indexOf(search_term) >= 0) {
$(this).show();
}
else {
$(this).hide();
}
});
});
这是非常缓慢的, 因为它在500 divs 中运行, 并搜索每个搜索_ term 属性, 以查看是否输入搜索术语。 是否有更好的或更快的方法可以做到这一点? 我甚至有兴趣使用更好的搜索机制 。
我可以根据需要修改DOM
EDIT Sorry I should have mentioned that say the search term is "hello today johnny", the term "hello", "today" and "johnny" would have to return true, this is why I was using indexOf in the script above.