Jquery-ui autocomplete dropdown below each word

前端 未结 3 1195
小鲜肉
小鲜肉 2021-01-31 00:33

I\'m using Autocomplete from jquery-ui. In the multiple values, you can get dropdown list for each word after space, but the dropdown appears at the size of the input box. Is it

3条回答
  •  借酒劲吻你
    2021-01-31 01:16

    I've based the answer on the answer to this question. As mentioned in that answer, IE<9 will need some extra code to make this work.

    Basically you create a span into which you write out the contents of the input element. You then use the width of this span to calculate the offset. JqueryUI provides a position hook where you can actually offset the value. so the HTML

    
    

    And the JS

        var query= $("#query");
        var faux = $("#faux");
        query.autocomplete({
            source: mySource
        }).on("keydown", function() {
            var off = query.selectionStart;
            faux.text(query.val().substring(0, off).replace(/\s/g, "\u00a0"));
            query.autocomplete("option", "position", 
                  {my: "left top", at: "left+" + faux.outerWidth() + " bottom"});
        });
    

    Working JSFiddle

提交回复
热议问题