jQuery autoComplete view all on click?

后端 未结 22 1865
北恋
北恋 2020-12-02 09:52

I\'m using jQuery\'s autocomplete in a relatively simple way:

$(document).ready(function() {
  var data = [ {text: \"Choice 1\"}, 
               {text: \"Ch         


        
相关标签:
22条回答
  • 2020-12-02 10:19

    I have seen all the answers which seem to be complete.

    If you want to get the list when the cursor is in the text field OR when you click on the matching label, here how you can do:

    //YourDataArray = ["foo","bar"];
    $( "#YourID" ).autocomplete({
                source: YourDataArray 
            }).click(function() { $(this).autocomplete("search", " "); });
    

    this works fine in Firefox, IE, Chrome ...

    0 讨论(0)
  • 2020-12-02 10:20

    I guess a better option is to put $("#idname").autocomplete( "search", "" ); into the onclick paramter of the text box . Since on select, a focus is put in by jquery , this can be a workaround . Dont know if it should be an acceptable solution.

    0 讨论(0)
  • 2020-12-02 10:20

    I used this way:

    $("#autocomplete").autocomplete({
                    source: YourDataArray,
                    minLength: 0,
                    delay: 0
                });
    

    Then

    OnClientClick="Suggest(this); return false;"/>
    
     function Suggest(control) {
                    var acControl = $("#" + control.id).siblings(".ui-autocomplete-input");
                    var val = acControl.val();
                    acControl.focus();
                    acControl.autocomplete("search");
    
    0 讨论(0)
  • 2020-12-02 10:23
    <input type="text" name="q" id="q" placeholder="Selecciona..."/>
    
    
    <script type="text/javascript">
    //Mostrar el autocompletado con el evento focus
    //Duda o comentario: http://WilzonMB.com
    $(function () {
        var availableTags = [
            "MongoDB",
            "ExpressJS",
            "Angular",
            "NodeJS",
            "JavaScript",                
            "jQuery",
            "jQuery UI",
            "PHP",
            "Zend Framework",
            "JSON",
            "MySQL",
            "PostgreSQL",
            "SQL Server",
            "Oracle",
            "Informix",
            "Java",
            "Visual basic",
            "Yii",
            "Technology",
            "WilzonMB.com"
        ];
        $("#q").autocomplete({
            source: availableTags,
            minLength: 0
        }).focus(function(){            
           $(this).autocomplete('search', $(this).val())
         });
    });
    </script>
    

    http://jsfiddle.net/wimarbueno/6zz8euqe/

    0 讨论(0)
  • 2020-12-02 10:24

    I found this to work best

    var data = [
        { label: "Choice 1", value: "choice_1" },
        { label: "Choice 2", value: "choice_2" },
        { label: "Choice 3", value: "choice_3" }
    ];
    
    $("#example")
    .autocomplete({
        source: data,
        minLength: 0
    })
    .focus(function() {
        $(this).autocomplete('search', $(this).val())
    });
    

    It searches the labels and places the value into the element $(#example)

    0 讨论(0)
  • 2020-12-02 10:27
    $("#searchPkgKeyWord").autocomplete("searchURL",
            {
                width: 298,
                max: 1000,
                selectFirst: false
            }).result(function (event, row, formatted) {
                callback(row[1]);
            }).focus(function(){
                $(this).click(); //once the input focus, all the research will show
            });
    
    0 讨论(0)
提交回复
热议问题