我在jsp页面中使用了自动完成功能。
我要设置自动完成文本框中的第一个值。当用户离开文本框时,应选择第一个值。
我该怎么做呢?
HTML:
<input id="auto">
jQuery代码:
$(document).ready(function() {
$("#auto").autocomplete({
source: ['Cat', 'Dog', 'Squirrell', 'Lizard'],
select: function(event, ui) {
alert(ui.item.value);
}
});
});
下面给出了jsfiddle链接。
http://jsfiddle.net/andrewwhitaker/vFWUt/
发布于 2014-03-27 23:16:25
你能做这样的事吗?我不能100%确定如何以其他方式访问您的source:
数组,尽管可能有一种方法。
$(document).ready(function() {
var arr = ['Cat', 'Dog', 'Squirrell', 'Lizard'];
$("#auto").autocomplete({
source: ['Cat', 'Dog', 'Squirrell', 'Lizard'],
select: function(event, ui) {
alert(ui.item.value);
}
});
$("#auto").blur(function(){
if(this.value==""){
this.value = arr[0];
}
});
});
https://stackoverflow.com/questions/22691480
复制相似问题