在jquery mobile中自动完成组合框

时间:2013-05-30 13:49:02

标签: jquery jquery-mobile jquery-ui-autocomplete jquery-mobile-listview

我知道jQuery UI autocomplete-combobox小部件。但现在我正在寻找移动设备。据我所知,在使用jQuery Mobile时,我可以使用带有自动完成功能的选择框或列表视图。

jQuery Mobile中的控件是否与jQuery UI中的Autocomplete组合框一样?

我需要向用户提供一个下拉列表,他可以在其中键入以过滤可用选项或向下滚动以查看所有选项

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用

https://github.com/commadelimited/autoComplete.js

HTML:

 <div data-role="page" class="jqm-demos" id="mainPage">
        <p>
            <input type="text" id="searchField" placeholder="Categories">
            <ul id="suggestions" data-role="listview" data-inset="true"></ul>
        </p>
    </div>

的javascript:

 <script>
        var autocompleteData = $.parseJSON('[{"value":"AL","label":"Alabama"},{"value":"AK","label":"Alaska"},{"value":"CA","label":"California"},{"value":"CO","label":"Colorado"},{"value":"CT","label":"Connecticut"},{"value":"NC","label":"North Carolina"},{"value":"ND","label":"North Dakota"},{"value":"NI","label":"Northern Marianas Islands"},{"value":"OH","label":"Ohio"},{"value":"OK","label":"Oklahoma"},{"value":"OR","label":"Oregon"},{"value":"PA","label":"Pennsylvania"},{"value":"PR","label":"Puerto Rico"},{"value":"RI","label":"Rhode Island"},{"value":"WV","label":"West Virginia"},{"value":"WI","label":"Wisconsin"},{"value":"WY","label":"Wyoming"}]');

        $("#mainPage").bind("pageshow", function (e) {
            $("#searchField").autocomplete({
                target: $('#suggestions'),
                source: autocompleteData,
                callback: function (e) {
                    var $a = $(e.currentTarget);
                    $('#searchField').val($a.data('autocomplete').value);
                    $("#searchField").autocomplete('clear');
                },
                link: 'target.html?term=',
                minLength: 1
            });
        });
    </script>

我在

中发布了其使用示例

https://stackoverflow.com/questions/34164377/how-to-use-jquery-mobile-autocomplete-plugin-with-jqgrid