jQuery UI自动完成返回[object Object]

时间:2013-06-18 16:35:35

标签: jquery user-interface jquery-ui-autocomplete

我正在尝试使用jQuery UI Autocomplete插件创建类似于Google的网站搜索。问题是我的网站搜索字符串“[object Object]”而不是我点击的值。每个选项都返回:“您搜索”[object Object]“与任何产品都不匹配。”

<script>
$(function () {
    var availableTags = [
        "SEO",
        "Responsive Web Design",
        "Google Local",
        "Twitter",
        "Social Media",
        "Web Design",
        "What is Google Authorship",
        "NFL",
        "Contact Advanced IFX",
        "Search Engine Optimization",
        "Kevin Sullivan",
        "Fantasy Football RB Rankings 2013",
        "Fantasy Football",
        "How to Buy Twitter Followers",
        "Advanced IFX",
        "Social Media Marketing",
        "Advanced Marketing Trends",
        "NFL Schedule 2013-2014 Season",
        "Fantasy Football Breakdown",
    ];
    $(".search_box").autocomplete({
        source: availableTags,
        select: function (event, ui) {
            var searchTerm = ui.item;
            $('.search_box').val(searchTerm);
            $('form.search').submit();
        }
    });
});

1 个答案:

答案 0 :(得分:0)

保持行

$('.search_box').val(searchTerm);

但是将上一行更改为

var searchTerm = ui.item.label;

那就行了。

查看这个小提琴的日志:http://jsfiddle.net/Ntb7G/