javascript - 'focus'什么时候调用 'autocomplete'

标签 javascript jquery

来自 http://jqueryui.com/demos/autocomplete/ 的“焦点”文档状态:

focusType:autocompletefocus Before focus is moved to an item (not selecting), ui.item refers to the focused item. The default action of focus is to replace the text field's value with the value of the focused item, though only if the focus event was triggered by a keyboard interaction. Canceling this event prevents the value from being updated, but does not prevent the menu item from being focused.

Code examples

Supply a callback function to handle the focus event as an init option. $( ".selector" ).autocomplete({ focus: function(event, ui) { ... } }); Bind to the focus event by type: autocompletefocus. $( ".selector" ).bind( "autocompletefocus", function(event, ui) { ... });

使用下面的代码在所有自动完成元素上设置一个名为“mytag”且值为“tester”的属性,即使我尚未选择这些元素。为什么属性“focus”不只在其中一个下拉菜单获得焦点时添加,而是在页面加载时添加?

 $("#myDiv").autocomplete({
    source: availableTags,
    focus: function(event, ui) {
        $(".ui-autocomplete li").attr("mytag", "tester");
    }
  });

最佳答案

当用鼠标悬停在建议的完成上或使用箭头键选择一个时。这是一个正常的“焦点”,应用于自动完成框。
自己尝试一下:http://jsfiddle.net/qk9gv/ !

关于javascript - 'focus'什么时候调用 'autocomplete',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12391627/

相关文章:

javascript - 显示/隐藏 iPad 的功能切换

javascript - 这段代码有内存泄漏吗?如果是这样,我该如何删除它?

javascript - 如何让 Apple Javascript Split Flap Counter 在纯 CSS 上运行

javascript - 如何避免 iPhone 页脚出现奇怪的图案?

javascript - 通过 WEBGL_depth_texture 渲染缓冲区对象和深度纹理有什么区别?

javascript - ScrollTop 闪烁 - Internet Explorer

jquery - 如何在调整页面大小后使图像与文本保持在一起?

javascript - 随机播放一组图像jquery

JavaScript 根据星期几更改 div 的 CSS 属性

javascript - 通过 GCM 在渐进式网络应用程序中推送通知