jQuery UI自动完成提交onclick结果 [英] jQuery UI autocomplete submit onclick result

查看:82
本文介绍了jQuery UI自动完成提交onclick结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户从自动填充选项中选择结果时,我一直在试图弄清楚如何提交表单。它需要单击鼠标或输入按钮。我看到那里的例子,但总是分片。没有人显示整个功能。

I've been trying to figure out how to submit the form when the person selects the result from choices of the autocomplete. It needs to work with a mouse click or enter button. I see examples out there but always in pieces. No one shows the entire function.

我在下面有这个代码,但是我得到错误,说结果不是函数。我不知道如何将它结合起来做我想做的事情。任何帮助都表示赞赏。

I have this code below but I get errors saying result is not a function. I don't know how to combine this to do what I would like. Any help is appreciated.

jQuery(document).ready(function(){  

jQuery("#vsearch").autocomplete("ajax/search.php",
    {
    minLength: 2
}
);
jQuery("#vsearch").result(function(event, data, formatted) {
      jQuery('#vsearch').value( formatted );
      jQuery('#search').submit();
});
});


推荐答案

来自: http://api.jqueryui.com/autocomplete/#event-select


选择 - 输入:autocompleteselect

select - Type:autocompleteselect

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

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.

代码示例

提供一个回调函数来处理
select事件作为init选项。

Supply a callback function to handle the select event as an init option.

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

按类型绑定到select事件:
autocompleteselect。

Bind to the select event by type: autocompleteselect.

$( ".selector" ).bind( "autocompleteselect", function(event, ui) {
  ...
});


所以你会使用:

编辑:(如果用户未选择任何内容,则进行修改)

(modified in case user does not select anything)

$("#vsearch").autocomplete({
    source: "ajax/search.php",
    minLength: 2,
    select: function(event, ui) {
        if(ui.item){
            $('#vsearch').val(ui.item.value);
        }
        $('#search').submit();
    }
});

如果我确定你想要做什么。

If I am sure of what you are wanting to do.

这篇关于jQuery UI自动完成提交onclick结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆