2014-09-10 2 views
0

http://jsfiddle.net/9R4cV/116/텍스트 상자에 시작 문자 만 입력해야하는 자동 완성 방법은 무엇입니까?

내가 문자 "A"는 단어의 중간에있는 경우에도 "A"의 목록을 입력하지만 난 단지 "는"어떤 사람이 나에게주십시오 솔루션의 말을 시작해야하는 경우이 바이올린 자동 완성에

안녕 frnds입니다 . 당신이 사용할 수있는 documentation에서

$(document).ready(function() { 

    var aTags = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9", "westerners", "sport"]; 
    $("#tags").autocomplete({ 
    source: aTags 
    }); 
}); 
+1

http://jsfiddle.net/9R4cV/117/ 업데이트 된 바이올린. 설명서는 다음과 같습니다. http://api.jqueryui.com/autocomplete/#event-search – Jack

답변

2

내가 업데이트 당신의 바이올린 http://jsfiddle.net/9R4cV/119/

더 많은 정보를 원하시면,이 답변을 참조하십시오 : 여기 https://stackoverflow.com/a/2405109/3810453

는 구현입니다 :

$(document).ready(function() { 

    var aTags = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9", "westerners", "sport"]; 

    $("#tags").autocomplete({ 
     //source option can be an array of terms. In this case, if 
    // the typed characters appear in any position in a term, then the 
    // term is included in the autocomplete list. 
    // The source option can also be a function that performs the search, 
    // and calls a response function with the matched entries. 
    source: function(req, responseFn) { 
     var re = $.ui.autocomplete.escapeRegex(req.term); 
     var matcher = new RegExp("^" + re, "i"); 
     var a = $.grep(aTags, function(item,index){ 
      return matcher.test(item); 
     }); 
     responseFn(a); 
    } 
}); 
}); 
0

, 사용자 정의 소스 :

var aTags = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9", "westerners", "sport"]; 
$("#tags").autocomplete({ 
    source: function(request, response) { 
    var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(request.term), "i"); 
    response($.grep(aTags, function(item){ 
     return matcher.test(item); 
    })); 
    } 
}); 
관련 문제