[英]Make jquery autocomplete not to fill the input value with the label of selected item
有没有办法让jquery自动完成插件只响应“select”回调,而不是用户选择后用所选项目的标签值填充目标输入?
我正在努力,但仍然没有成功,等待帮助......
问候。 拉里
我知道这是一个老问题但是,对于不想使用setTimeout函数的人来说,解决方案是将属性ui.item.value更改为“”
代码 :
$('#ac').autocomplete({
source : ["hello", "how", "do", "you", "do"],
select: function(event, ui){
if (ui.item && ui.item.value){
ui.item.value="";
}
}
})
请尝试以下代码;)
$('#ac').autocomplete({
source : ["hello", "how", "do", "you", "do"],
close: function(event, ui){
$('#ac').val('');
}
});
如果源数组是具有“label”和“value”属性的对象数组,则插件会为您处理此问题。
请参阅jQuery api以获取自动完成功能 :
$('#autocomplete').autocomplete({ source: [ { label: 'This is a descriptive label' , value: 'Just the value' } ,{ label: '2 is better than one' , value: '2'} ,{ label: 'third times the charm' , value:'Three' } ] })
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script> <input type='text' id='autocomplete'>
SO的代码片段不喜欢它,但它有效
这是一种更简单的方法(使用experimentX的代码):
$('#ac').autocomplete({
source : ["hello", "how", "do", "you", "do"],
select: function(event, ui){
$('#ac').css('color','white');
}
})
$('#ac').autocomplete({
source : ["hello", "how", "do", "you", "do"],
select: function(event, ui){
setTimeout(function (){
$('#ac').val('');
}, 1000)
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.