jQuery UI Autocomplete autoFocus not working

爱⌒轻易说出口 提交于 2019-12-12 09:38:10

问题


I am using jQuery UI autocomplete and trying to implement the autoFocus option.

The documentation states the following: If set to true the first item will be automatically focused.

I created a basic example and cannot get to work. I must be missing something obvious. See here: http://jsfiddle.net/9bQJX/

$("#autocomplete").autocomplete({
    source: [
        "ActionScript",
        "AppleScript",
        "Asp",
        "BASIC",
        "C",
        "C++",
        "Clojure",
        "COBOL",
        "ColdFusion",
        "Erlang",
        "Fortran",
        "Groovy",
        "Haskell",
        "Java",
        "JavaScript",
        "Lisp",
        "Perl",
        "PHP",
        "Python",
        "Ruby",
        "Scala",
        "Scheme"
    ],
    autoFocus: true
});

回答1:


You're using an old version of jQueryUI (1.8.9). The option works fine with 1.8.16. In fact, according to the changelog, the autoFocus option was added in 1.8.11, so you should be good with any version >= 1.8.11.

See an updated example using 1.8.16: http://jsfiddle.net/Bqujj/




回答2:


Open Jquery-ui.js file and search for "autocomplete". Change "autoFocus" to "true". e.g.

$.widget ( "ui.autocomplete", {
   version: "1.12.1",
   ...
   ...
   options: {
      ...
      ...
      autoFocus: true,
      ...
      ...

Screen shot of config




回答3:


keep autoFocus = true, before source option. eg like below.

$("#autocomplete").autocomplete({
    **autoFocus : true,**
    source: [
        "ActionScript",
        "AppleScript"
    ]
})


来源:https://stackoverflow.com/questions/8249509/jquery-ui-autocomplete-autofocus-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!