jQuery-UI自动完成从下拉列表中的项目单击提交表单 [英] jQuery-UI Autocomplete submitting form onclick of item from dropdown list

查看:64
本文介绍了jQuery-UI自动完成从下拉列表中的项目单击提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQueryUI的功能,我无法弄清楚如何有当一个项目被选中我的形式提交.

I'm using the jQueryUI autocomplete() function and I can't figure out how to have my form submit when an item is selected.

我认为问题出在select: event上,但我是jQueryUI的新手,无法弄清楚如何实现此功能.

I think the issue is with the select: event but I'm new with jQueryUI and can't figure out how to make this work.

这是我的代码,在其他情况下也可以正常工作

Here's my code which works fine otherwise:

            <script type="text/javascript">
            $(document).ready(function() {
                $(function() {
                    $( "#search_box" ).autocomplete({
                        source: function(request, response) {
                            $.ajax({ url: "<?php echo site_url('autocomplete/suggestions'); ?>",
                            data: { term: $("#search_box").val()},
                            dataType: "json",
                            type: "POST",
                        success: function(data){
                            response(data);
                        },
                        select: function (event, ui) {
                                $(event.target).val(ui.item);
                                $('#search_form').submit();
                                return false;
                            }
                        }); 
                    },          
                    minLength: 1 
                    });
                });
            }); 
            </script>

任何帮助将不胜感激!

推荐答案

安德鲁(Andrew)是正确的,请参见小提琴他提及.如果将带有"ui.item"的部件切换为"ui.item.value",则select:function()现在可以正常工作.

Andrew was correct, see the fiddle he mentioned. If you switch the part with "ui.item" to "ui.item.value" the select: function() now works perfectly.

这篇关于jQuery-UI自动完成从下拉列表中的项目单击提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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