Jquery AutoComplete - 将等于原始 SelectBox 值的链接添加到下拉列表

发布于 2024-09-06 17:09:03 字数 655 浏览 2 评论 0原文

我正在尝试修改此示例: http://jqueryui.com/demos/autocomplete/#combobox 解析类似的选择列表,其中超链接作为值传递。

<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>
...

所需的效果是一旦匹配完成并且用户单击输入或仅当用户单击自动完成列表中的建议时激活到相应页面的链接。

我还尝试让 AutoComplete 解析一个简单的链接列表而不是选择列表,但考虑到我新的 jquery 技能,这对我来说似乎太过破解。

任何帮助将不胜感激。 非常感谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光匆匆的小流年 2024-09-13 17:09:03

使用自动完成选择事件导航到页面

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

来自 jQueryUI 文档:

从菜单中选择某个项目时触发; ui.item 指所选项目。 select 的默认操作是将文本字段的值替换为所选项目的值。取消此事件会阻止更新该值,但不会阻止菜单关闭。

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.

最后的乘客 2024-09-13 17:09:03

尝试将 onItemSelect 回调添加到自动完成功能中。
类似的东西

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

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

onItemSelect: function(v){
   window.location.href = v;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文