jQuery UI自动完成选择 [英] jQuery UI Autocompleteselect

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

问题描述

我试图让用户单击Enter或单击鼠标时提交表单.我已经看到了一些示例以及jQuery UI网站上的示例.我要跟踪的示例是 jQuery UI自动完成提交onclick结果.因此,我的代码如下所示.

I am trying to get my form to submit when a user either clicks enter or mouse clicks. I have seen some examples as well as the example on the jQuery UI site. The example that I am following is jQuery UI autocomplete submit onclick result. Therefore my code looks like this.

<script type="text/javascript">
$(document).ready(function() {
    $("#myInput").autocomplete({
        source: "fh_autocomplete_search.php",
        minLength: 2,
        select: function(event, ui) {
            if(ui.item){
                $("#myInput").value(ui.item.value);
            }
            $("#myInput").submit();
        }
    });
    $( "#myInput" ).bind( "autocompleteselect", function(event, ui) {

    })
});
</script>

我不确定代码的.bind部分下应该包含什么内容.或什至实际上它正在做什么.而且我一直在这里阅读,但仍然只是不单击 http://api.jquery.com/bind/当我在其下放置一个警报并从#myInput框中选择一个ui.item时,警报确实消失了.但是什么也没有填满或提交.如果我在if(ui.item)部分下放置一个警报,该警报不会消失.如果有人可以向我解释发生了什么,并建议在.bind部分下放置一些代码,我将不胜感激.

I'm not sure what should go under the .bind section of the code. Or really what it is even doing. And I have been here and read it but still just not clicking http://api.jquery.com/bind/ When I put an alert under it and select a ui.item from the #myInput box the alert does go off. But nothing fills or submits. If I put an alert under the if(ui.item) part it doesn't go off. If someone could explain to me what is going on and suggest some code to put under the .bind section I would greatly appreciate it.

推荐答案

如果表单的ID为myForm:

$(document).ready(function() {
    $("#myInput").autocomplete({
        source: "fh_autocomplete_search.php",
        minLength: 2,
        select: function(event, ui) {
            $("#myInput").val(ui.item.value);
            $("#myForm").submit();
        }
    });
});

另请参见此示例.

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

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