JQuery AutoComplete - 自定义输出

时间:2014-01-21 16:50:30

标签: javascript jquery autocomplete

我有以下代码:

$("#search-field").autocomplete({
   appendTo: "#box",
      source: function(request, response){
          $.ajax({
              url: "http://ff.search.yahoo.com/gossip",
              dataType: "jsonp",
              data: {
                  "output": "jsonp",
                  "command": request.term
              },
        success: function(data) {
                  var suggestions = [];

                  $.each(data.gossip.results, function(i, val) {
                      suggestions.push(val.key);
                  });

                  response(suggestions);

              }
          });
      }
  });

基本上,当您输入几个字母时,自动完成功能会按以下方式返回10个项目:

<li class="ui-menu-item" role="presentation">
 <a id="ui-id-12" class="ui-corner-all" tabindex="-1">Returned Text</a>
</li>

如何编辑我的代码,以便输出如下链接:

<li class="ui-menu-item" role="presentation">
 <a href="http://www.searchlotto.co.uk/2012/yhs_search.php?q=RETURNED TEXT&cid=" id="ui-id-12" class="ui-corner-all" tabindex="-1">Returned Text</a>
</li>

1 个答案:

答案 0 :(得分:-2)

每次推送后,您需要使用Jquery查找插入的锚标记并更新其上的href