我正在使用自动填充显示自动提示,结果正在显示。
代码:
$("#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 foreach锚标记。
我如何实现这一目标?
<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>
答案 0 :(得分:1)
您可以使用onfocus并在每个onfocus事件上附加autosuggest html。
感谢。
答案 1 :(得分:0)
这就算了
select:function(event,ui){
location.href="my URL part/"+ui.item.id+"other url part/"+ui.item.name;
}