我设法启动并运行了一些东西,这就是我最终得到的结果:
var do_live_search = function() {
var stopwords = new Array("a","about","an","and","are","as","at","be","by","but","can't","from","how","i","in","is","it","of","on","or","that","the","this","to","was","we","what","when","where","which","with","won't");
var keywords = $("#Trigger").val().split(" ");
var clean_keywords = new Array();
$.each(keywords,function(i,val){
if(($.trim(val) != "")
&& ($.inArray(val,stopwords)==-1)
&& ($.inArray(val,clean_keywords)==-1)
&& (val.length > 3)
){
clean_keywords.push(val);
}
});
if (clean_keywords.length >= 1) {
var joined_keywords = clean_keywords.join('|');
$.get("/fetch/_search_support_faqs?q="+joined_keywords+"", function(mydata){
if (mydata != "") {
$.each(mydata, function(i, item) {
$('#MatchingFAQs ul').append(
$('<li>').append(
$('<a>').attr('href','#FAQ_'+mydata[i].entry_id).append(mydata[i].title)
));
});
$('#MatchingFAQs').slideDown('slow');
}
});
}
}
然后使用 jQuery 的“Type Watch”插件(https://github.com/dennyferra/TypeWatch)触发了这一点:
var typewatch_options = {
callback:do_live_search,
wait:500,
highlight:true,
captureLength:3
}
// Watch for key up events in the search field
$("input#Trigger").typeWatch(typewatch_options);