问题描述:

<input class ="metro" type="text" name="city">

This is input tag as a child of which I need to append an unordered list which is passed as an array to a function call as follows

$("input").autoComplete(["agra","bombay","delhi","chennai"]);

This autocomplete function accepts an array and outputs its elements as an unorederd list which I am not able to do.

网友答案:

$("input").autoComplete({source:["agra","bombay","delhi","chennai"]});

Ref

网友答案:

Demo

$(function () {
    var availableCities = [
        "agra",
        "bombay",
        "delhi",
        "chennai"
    ];

    $("input.metro").autocomplete({
        source: availableCities
    });
});

or

$(function () {
    $("input.metro").autocomplete({
        source: [
            "agra",
            "bombay",
            "delhi",
            "chennai"]
    });
});

Demo

API DOCS

网友答案:

If you want to implement the function on your own, the basic block would be as follows

$(function () {
    var Cities = [
        "agra",
        "bombay",
        "delhi",
        "chennai"
    ];

    $("input.metro").autocomplete({
        $(this).append("<ul>");
        for(i=0;i<Cities.length;i++){
            $(this).children("ul").append("<li>Cities[i]</li>");
        }
        $(this).append("</ul>");

    });
});
相关阅读:
Top