autocomplete jquery中的自定义ul li

时间:2017-02-28 06:50:56

标签: javascript jquery html

我使用jquery自动完成:

<form id="searchForm" action="https://www.google.com/#q=" method="get">
        <input id="input_submit" class="input_search" type="text" name="q" placeholder="Search...">
        <input class="input_submit" type="submit" value="SEARCH">
        <span id="myAutocompleteMsg"></span>
 </form>

使用js代码:

<script language="javascript" type="text/javascript">
        $(document).ready(function() {
            $('#searchForm').submit(function(e) {
                e.preventDefault();
                var search = $('.input_search').val();
                var url = $(this).attr('action');
                // alert('search=' + search + ' url=' + url);
                console.log(x, "s");
                window.location.href = url + search;
            });

            $("#input_submit").autocomplete({
                source: ["yegane", "salami", "ali", "alpha"],
            });

            $("#input_submit").on("keyup", function() {
                //console.log("typing");
                setTimeout(function() {
                    if (($(".ui-autocomplete").css("display") == "none") && ($("#myAutocomplete").val() != "")) {
                        console.log("No result!");
                        $("#ui-id-1").html("Sorry!The url is not avaible");
                    } else {
                        $("#myAutocompleteMsg").html("");
                    }
                });
            });
        });

我已尝试过上面的代码。但是如何在自定义ul li中呈现结果,如果结果在数组中显示为ul li但是如果结果不在数组中显示为“无结果”,则为ul li to。

0 个答案:

没有答案