V
V
Valeriy19972015-09-08 11:05:57
JavaScript
Valeriy1997, 2015-09-08 11:05:57

How can I make the first item in the list have focus?

There is a search script, it gives out the matched elements in a list. When you hover over an element , it acquires focus . But the app will only function with the virtual keyboard, no mouse. How to make the first element automatically in focus (this is necessary so that when you press the virtual enter key with emulate a click on it)

Here is the markup of the input:

<input id="myinput" type="text" class="form-control" placeholder="Введите слово для поиска" name="phone" required/>


here is the search script:

$("#myinput").autocomplete({
    minLength: 0,
    source: projects,
    focus: function (event, ui) {
        $("#myinput").val(ui.item.label);
        return false;
    },
    select: function (event, ui) {
        $("#myinput").val(ui.item.label);
        $("#myinput-id").val(ui.item.value);
        $("#myinput-description").html(ui.item.desc);
        $("#myinput-icon").fadeOut('slow', function () {
            $(this).attr("src", "images/" + ui.item.icon).fadeIn('slow');
        });

        return false;
    }
})
    .data("autocomplete")._renderItem = function (ul, item) {
    return $("<li></li>")
        .data("item.autocomplete", item)
        .append("<a>" + item.label + "<br>" + item.desc + "</a>")
        .appendTo(ul);
};


Here is the full version: jsfiddle.net/t52ka/70

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2015-09-08
@Valeriy1997

html5 autofocus

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question