获取jQuery的自动完成功能的模糊选定值 [英] Get the selected value in jquery autocomplete on blur function

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

问题描述

我想有自动完成功能,这里的文本框应该得到填充值列表作为第一个项目时,有一个模糊的事件。

I want to have auto complete functionality, where the text-box should get populated with the value list as a first item when there is an blur event.

我想有相同的功能在这个链接环节实施

I would like to have the functionality same as implemented in this link link

我有以下code,它在填充选项卡并输入键,但不知道如何在模糊事件实现相同的功能。

I have the code below, which populates on tab and enter key, but dont know how to achieve same functionality on blur event.

$( "#statelist" ).autocomplete({
    autoFocus: true,
    source: states,
    select: function (event, ui) {
        stateid = (ui.item.lable);
        $("#stateid").val(stateid);
    }
});

编辑: -
用户输入文本让我们说类型切,并没有pressing选项卡或回车键,用户移动他的控制下一个文本框,在这种情况下我想第一个列表项在文本框中自动填充。

EDIT :- user enters a text lets us say type "che" and without pressing tab or enter key, user moves his control to next textbox, in this scenario I want the first list item to populated automatically in the textbox.

推荐答案

您可以在模糊事件发送回车键。

You can send a enter key on blur event.

     $( "#statelist" ).blur(function(){
         var keyEvent = $.Event("keydown");
         keyEvent.keyCode = $.ui.keyCode.ENTER;
         $(this).trigger(keyEvent);
     }).autocomplete({
         autoFocus: true,
         source: states,
         // ...
     });

下面是小提琴: http://jsfiddle.net/trSdL/4/

这里是一个类似的问题。
<一href=\"http://stackoverflow.com/a/15466735/1670643\">http://stackoverflow.com/a/15466735/1670643

And here is a similar question. http://stackoverflow.com/a/15466735/1670643

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

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