如何在运行时动态更改自动完成的 HTML 代码?

How to change HTML code of autocomplete dynamically at runtime?

我正在使用自动完成功能显示自动建议,结果正在显示。

代码:

$("#suggest").autocomplete({
delay: 20,
source: function(request, response) {
    //alert(request.term);
  var suggestURL = myAutosuggesturl;
  suggestURL = suggestURL.replace('%QUERY', request.term);

  // JSONP Request
  $.ajax({
      method: 'GET',
      dataType: "json",
      async: true,
      url: suggestURL
    })
    .success(function(data){
        //alert(data.results);
      for (var i = 0; i < data.results.length; ++i){
         var htmltag=data.results[i]['value'];
         var firsthtag=htmltag.replace("<b>","");
         var secondhtag=firsthtag.replace("</b>","");
        console.log(data.results[i]['value']);
        //alert(secondhtag);
        //var a_href = $('a').attr('href','');
        data.results[i]['value']=secondhtag;

      }
      console.log(data.results);
      response(data.results);
    });
}

但问题是 HTML 是动态生成的,我需要为每个锚标记动态附加 href

如何实现?

     <ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-1" tabindex="0" style="display: none; top: 93px; left: 206px; width: 325px;">
<li class="ui-menu-item" role="presentation">
    <a id="ui-id-34" class="ui-corner-all" tabindex="-1">Game (By Neil Strauss)</a>
</li>
<li class="ui-menu-item" role="presentation">
    <a id="ui-id-35" class="ui-corner-all" tabindex="-1">Gone (By Michael Grant)</a>
</li>
  </ul> 

您可以使用 onfocus 并在每个 onfocus 事件上附加自动建议 html。

谢谢。

成功了

select:function(event,ui){ location.href="my URL part/"+ui.item.id+"other url part/"+ui.item.name; }