使用jquery autocomplete自动显示命题
我从jQueryUI实现了自动完成功能,它可以正常工作。 唯一的问题是我必须按下向下箭头才能看到命题 我希望这个能自动完成。这可能吗 到目前为止,我的代码是自动完成的使用jquery autocomplete自动显示命题,jquery,autocomplete,Jquery,Autocomplete,我从jQueryUI实现了自动完成功能,它可以正常工作。 唯一的问题是我必须按下向下箭头才能看到命题 我希望这个能自动完成。这可能吗 到目前为止,我的代码是自动完成的 function autoCompletion() { var splitUrl = document.URL.split('recherche'); $.ajax({ type: "POST", url: splitUrl[0] + "recherc
function autoCompletion() {
var splitUrl = document.URL.split('recherche');
$.ajax({
type: "POST",
url: splitUrl[0] + "recherche/autocomplete",
data: "auto="+$("#ville").val()
+"&academie_id="+$("#academie_id").val(),
success: function(retour){
var tags = retour.split(',');
$("#ville").autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
},
minLength: 1
});
}
});
}
如果您有文本输入,请执行以下操作:
$("#input_id").autocomplete({source: "search.php", minLength: 2, select: function(event, ui){
//do something here if needed after a element is select from the list.
});
它应该可以工作,您只需要让
search.php
返回信息。自动完成初始化的顺序应该是相反的。自动完成组件的初始化应该只发生一次,当页面加载时,查询应该自动执行。见所附代码:
$( "#ville" ).autocomplete({
source: function( request, response ) {
// Put your ajax request here
// Put your ajax request here
$.ajax({
type: "POST",
url: splitUrl[0] + "recherche/autocomplete",
data: "auto="+$("#ville").val()
+"&academie_id="+$("#academie_id").val(),
success: function(your_data){
// Call jquery callback
response( your_transformed_data );
}
});
}
});
将它设置为
onchange
事件,它应该可以工作:在onchange事件中,我需要在焦点之外才能启动查询,这就是为什么我使用onkeyup