Php jQuery自动完成忽略0

Php jQuery自动完成忽略0,php,jquery,html,autocomplete,Php,Jquery,Html,Autocomplete,用户输入值,如01234和12345。我希望在用户进入时忽略0 <input name="location" class="input-lg" style="width:100%;" id="location" type="text" size="50" placeholder="<?php echo $this->lang->line('inputhint');?>" /> $(function() { var availableLocat

用户输入值,如01234和12345。我希望在用户进入时忽略0

    <input name="location" class="input-lg" style="width:100%;" id="location" type="text" size="50" placeholder="<?php echo $this->lang->line('inputhint');?>" />

$(function() {
    var availableLocations = 
    <?php
        // print the json array containing all zips
        echo $locations;
    ?>

    $("#location").autocomplete({
        source: availableLocations,
        minLength: 3,
        focus: function (event, ui){
            $('#location').val(ui.item.value); 
            return false;
        },
        select: function (event, ui){
            $('#location').val(ui.item.value); // display the selected text
            $('#locationid').val(ui.item.key); // save selected id to hidden input
            return false;

        },
        change: function (event, ui){
            // write value to hidden field
            $( "#locationid" ).val( ui.item? ui.item.key : 0 );
            return false;
        }
    });
});

以下内容未经测试,但其工作原理如下:

$("#location").autocomplete({
    source: function(request, response) {
        // manipulate your search term
        var yourTerm = parseInt(request.term);
        // run a filter function on your data...
        var filteredArray = $.map(availableLocations, function(item) {
            // or whatever your matching rule is....
            if( item.startsWith(yourTerm)){
                return item;
            } else{
                return null;
            }
        });
        // return the filtered values
        response(filteredArray);
    }
});

是的,您可以使用源函数,request.term包含您的搜索字符串。谢谢Axel。我该怎么做呢。来源:函数(事件,ui){var zip=parseInt(ui.item.value);…}