简体   繁体   中英

how can i turn Jquery UI autocomplete into links?

i was trying out the jquery ui autocomplete and its pretty easy to implment and i loved it, but im finding it confusing to make the suggestions linkable just like google search,ie when you click on it it takes you to another page.

$(function() {  
            $("#state").autocomplete({
                source: "states.php",
                minLength: 2,
                select: function(event, ui) {
                    $('#state_id').val(ui.item.id);
                    $('#abbrev').val(ui.item.abbrev);
                }
            });
});

this is an example of the jquery script, thanks for your help:))

If I understand correctly, you just need a line like:

window.location="http://place/to/link/to.php?" + ui.item.abbrev; //This would send you to a php script accepting ui.item.abbrev as a parameter. 

in your select : function(event,ui){ ... }

you can add a callback function to the select event.

$( ".selector" ).autocomplete({
   select: function(event, ui) { ... }
});

there you could redirect to the link you want.

window.location.href = "http://stackoverflow.com";

Sorry I just saw you have already the callback function added. so you only need to redirect.

该示例将使您进入正确的位置: http : //jqueryui.com/demos/autocomplete/#custom-data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM