自动完成:只有当用户键入制表键时,才关注第一个项目
Autocomplete: first item focused only when the user type on tab key
通过使用jqueryUi
autocomplete
,我希望只有当用户键入tab key
时,第一个项目才会自动聚焦
我应该如何执行此任务
使用指定的autoFocus
option
true
初始化自动完成不符合我的目的!
有什么想法吗?
这是我的密码
有关更多详细信息,请参阅评论。
element.autocomplete({
minLength: 3,
// the following option "autoFocus = true"
// make the first item focused when the user type the first 3 letters
// I would like the first item focused only when I type on TAB
autoFocus: false,
source: function (request, response) {
// some code
}
}).data('autocomplete')._renderItem = renderItem;
// the following piece of code works only when I type the first three letters,
// If I type four letters and then tab it does not work!
element.on('keyup', function (event) {
if (event.keyCode === 9) {
element.autocomplete( "option", "autoFocus", true );
}
});
是的,autoFocus不会做你想做的事。相反,您可以伪造用户在想要选择项目时通常必须执行的按键。
element.keydown(function(e){
if( e.keyCode != $.ui.keyCode.TAB ) return; // only pay attention to tabs
e.keyCode = $.ui.keyCode.DOWN; // fake a down error press
$(this).trigger(e);
e.keyCode = $.ui.keyCode.ENTER; // fake select the item
$(this).trigger(e);
});
演示:http://jsfiddle.net/uymYJ/8/
相关文章:
- Jquery自动完成:如果没有选择任何项目,则使tab键选择第一个项目
- 自动完成:只有当用户键入制表键时,才关注第一个项目
- 用相同的键替换/更改项目
- 使用制表键时禁用只读文本框的光标焦点
- 如何在角度UI树中获取某个项目的键值或迭代
- 每个空格键 - 预览下一个和上一个项目
- 如何在 Javascript Metro 应用程序中检测列表视图中项目的右键单击
- 如何在HTML中的li项目上创建右键单击自定义菜单
- 用于使用 Tab 键选择项目的事件
- 右键单击树视图的项目时显示菜单
- 从浏览器获取制表键
- 在选择选项中选择多个项目,而不使用“Ctrl”键
- String.fromCodePoint()赢得'无法在IE中工作,无法使用制表键'不适用于Firefo
- 根据项目在ANGULAR中的键为其添加一个字符串
- 正则表达式转义制表键
- 如何在Asp.Net中不按CTRL键的情况下在ListBox中多选项目
- 有没有办法禁用制表键操作
- 如何在javascript中存储由键引用的项目列表
- 如何防止制表键触发keyup/keydown事件?
- 如何禁用除制表键以外的键盘上的所有键