开发者

Jquery AutoComplete - Add Links Equal to Original SelectBox value to DropDown List

I'm trying to modify this example: http://jqueryui开发者_开发技巧.com/demos/autocomplete/#combobox to parse a similar select list, in which hyperlinks are passed as values.

<select id="combobox">
<option value="/page1" title="Page1">Page1</option>
<option value="/page2" title="Page2">Page2</option>
<option value="/page3" title="page3">Page3</option>
<option value="/page4" title="Page4">Page4</option>
...

The effect desired is to activate the link to the corresponding page once a match has been made and the user clicks enter or simply when a user clicks the suggestion from the autocomplete list.

I've also tried to make the AutoComplete parse a simple link list instead of a select list but it seems too much of an hack to me, given my fresh jquery skills.

Any help will be appreciated. Thank you very much.


Use the autocomplete select event to navigate to the page

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

From the jQueryUI documentation:

Triggered when an item is selected from the menu; ui.item refers to the selected item. The default action of select is to replace the text field's value with the value of the selected item. Canceling this event prevents the value from being updated, but does not prevent the menu from closing.


try adding onItemSelect callback to the autocomplete. something along the lines of

onItemSelect: function(v){
   window.location.href = v;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜