开发者

jQuery ui autocomplete - renderItem url's

Using:

.data( "autocomplete" )._renderItem = function( ul, item ) {
                var temp = item.url.substring(16, item.url.length)
                return $( "<li></li>" )
         开发者_JAVA技巧       .data( "item.autocomplete", item )
                .append( "<a>" + item.value + "<br>" + item.url + "<br>" + item.description + "<br>" + "Support URL: " + item.support_url + "<br>" + "Contact: " + "<a href=" + item.contact + ">Test</a>" + "<br />" + "</a>"  )
                .appendTo( ul )

jQuery is parsing the item.url and automatically making that a href in the html. I'd like to manually control what becomes an href so that I can do something like "<a href='" + item.url + ">" + item.title "</a>"

The way jQuery handles that now is making item.url an href and adding my html href and not using the title properly.

In an older version of autocomplete I was able to do a .result(function(event, item) { location.href = item.url; }); but that doesn't seam to be supported here.


You can supply a callback that will be executed when an item is being selected.

$("#input").autocomplete({
    source: mySource, 
    select: function(event, ui){
        window.location = ui.item.url;
    }
});

Ref: http://docs.jquery.com/UI/Autocomplete#event-select

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜