它不检查比赛的顺序,但你可以试试这个:
http://jsfiddle.net/tEJdx/5/
var possible = [
'admin_controller',
'accommodation',
'printer',
'advertised',
'aoc', // this will match even if it's in wrong order
];
$('input').keypress(function(){
setTimeout( function() {
var result = [], input = $('#input').val();
possible.filter(function(element, index, array) {
var count = 0;
for( i in input ) {
if( element.indexOf( input[i] ) != -1 )
count++;
}
if( count == input.length )
result.push( element );
});
$('#result').html(result.join('<br/>'));
}, 200);
});
使用这样的 HTML:
<input id="input" />
<div id="result"></div>