$('#container form').delegate('#addSearch', 'keyup', function(e) {
var tmpVAL = $('#addSearch').val();
$('.w').each(function() {
var tmpHTML = $(this).html();
if (tmpHTML == tmpVAL) {
$(this).fadeIn(250);
} else if (tmpVAL.length < 1) {
$(this).fadeIn(250);
} else {
$(this).fadeOut(250);
}
});
});
和#addSearch
是 <input type="text">
.
所以,我的问题是;显然,这只会返回与 tmpVAL
完全匹配的结果。 - 我怎样才能允许每个字母都会改变搜索结果。
例如
我输入N
它提出了 No, Not, Nothing, Nothingness
我输入NOT
它提出了 Not, Nothing, Nothingness
任何帮助将不胜感激,我想这将是正则表达式?
最佳答案
$(function() {
$('#container form').delegate('#addSearch', 'keyup', function(e) {
var tmpVAL = $('#addSearch').val();
$('.w').each(function() {
var tmpHTML = $(this).text();
var subSection = tmpHTML.substring(tmpVAL.length, 0);
if (subSection == tmpVAL && tmpVAL != '' ) {
$(this).show();
} else {
$(this).hide();
}
});
});
});
关于javascript - 自动完成(自动过滤?),使用 jQuery 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5020940/