jQuery UI自动完成功能不起作用

时间:2014-10-03 06:32:26

标签: jquery jquery-ui jquery-ui-autocomplete

我试图在自动填充中使用jQuery UI,但它没有显示任何列表或任何内容。据我所知,没有必要用jQuery UI声明ulli

<html>
    <head>
        <link href="./jquery-ui.css" rel="stylesheet">

        <script src="./jquery-1.11.1.js"></script>
        <script src="./jquery-ui.js"></script>
    </head>

    <body>
        <input id="pu_location" size="38"  type="text" />                               
        <input type="hidden" id="pu_locationID" />

        <script>
            Script is below.
        </script>
    </body>
</html>

脚本:

 <script>

$( document ).ready(function() {

        $("#pu_location").autocomplete({

            source: function(request, response) {

            $.getJSON("/test.php", { country_code: "USA",term:$('#pu_location').val()}, 
                      function(data) {
                        alert(data[0].id);
                        var array =[];
                        for(key in data){
                            if (data[key].label!=''){
                                array.push(data[key].label);
                                }
                            }
                            alert(array);
                            response(array);
                        });
            },
            delay: 100, 
            minLength: 3                        
            });
}); 
</script>

顺便说一下,data是完美的。 alert表明一切都很好。

编辑: 它现在适用于Chrome,但不适用于Firefox!

1 个答案:

答案 0 :(得分:0)

第一条线索: 删除:

$(function() {

你试图在这里创建selfexecuting js函数,但这没有必要,因为你已经准备好了函数 - annonymus函数。

然后在行

之前放一个日志
$("#pu_location").autocomplete({

只是为了确保正在执行此代码。

第二条线索:你在关于响应的数据,然后你创建和填充数组,最后你传递给响应数据,那么这个处理的意义是什么?

相关问题