打开自动填充结果'文本框上的div单击

时间:2010-09-02 07:09:39

标签: jquery jquery-autocomplete

我正在使用此插件进行自动填充

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete

我希望当用户点击文本框时,包含所有结果的div

我尝试使用$("#textbox").search()但无效

我该怎么办?

感谢

3 个答案:

答案 0 :(得分:1)

以下是farrukhaziz关于如何将此功能添加到插件的教程:http://plugins.jquery.com/node/10336

您需要编辑插件源代码。

将“LaunchManual”部分添加到源的此部分。

        flushCache: function() { 
                return this.trigger("flushCache"); 
        }, 
        setOptions: function(options){ 
                return this.trigger("setOptions", [options]); 
        }, 
        unautocomplete: function() { 
                return this.trigger("unautocomplete"); 
        }, 
        launchManual: function() {                         //ADD THIS
                return this.trigger("launchManual"); 
        }

和本节中的'LaunchManual'位:

        }).bind("flushCache", function() { 
                cache.flush(); 
        }).bind("setOptions", function() { 
                $.extend(options, arguments[1]); 
                // if we've updated the data, repopulate 
                if ( "data" in arguments[1] ) 
                        cache.populate(); 
        }).bind("unautocomplete", function() { 
                select.unbind(); 
                $input.unbind(); 
                $(input.form).unbind(".autocomplete"); 
        }).bind("launchManual", function() {              //ADD THIS
                if( !cache.load( $input.val() ) ) 
                { 
                        cache.flush(); 
                        cache.populate(); 
                } 
                lastKeyPressCode = KEY.DOWN; // equivalent of 40 (down arrow) 
                onChange(0, true); 
        });

然后你可以调用该函数来显示下拉列表:

$('#textbox').click(function() {
   $(this).launchManual();
});

答案 1 :(得分:0)

试试这个:

$('#textbox').click(function() {
   $(this).trigger('focus');
});

答案 2 :(得分:0)

尝试一下:

var input = $('#myinput');

input.autocomplete(data, {minChars: 0});
input.focus(function(){ input.keypress(); });