jQuery自动完成到jQuery UI的自动完成迁移(jQuery 1.2).X到2.x)

jQuery Autocomplete to jQuery UI Autocomplete migration (jQuery 1.2.x to 2.x)

本文关键字:jQuery UI 迁移      更新时间:2023-09-26

我正在尝试迁移一个旧的脚本使用最新的jQuery .ui.autocomplete.js和jQuery 2.1.1(加载jQuery - migration -1.2.1.min.js帮助,但我不希望使用它)。

这是我想做的,找到:

$("input").autocomplete(["a", "b", "c"]);

改为:

$("input").autocomplete({
  source: ["a", "b", "c"]
});
  • 每个jQuery自动完成迁移指南

下面是我的三段旧代码:

$("#county").autocomplete(CountyArray, {            
        width: 170,
        matchContains: false,
        selectFirst: false
    }).result(function(event, data, formatted) {
        if($("#county").val()!=''){
            $("#place").val('');
            $("#street").val('');
            $('#islike').val('0');
            LoadPlaceListNew(0);
        }
    });

$("#street").autocomplete(siteURL+"auto_street.php?county="+county+"&place="+place,{
        width: 260,
        selectFirst: false      
    }).result(function(event, data, formatted) {        
            $("#street").val(formatted.split(" (")[0]);
            if($("#street").val()!=''){ 
                LoadZipcodesNew(0);
            }           
    });

提前感谢!

我们弄清楚了,只需要最新的jQuery和jQuery .ui.autocomplete.js (jQuery - migration -1.2.1.min.js是一个完全不必要的解决方案):

$("#county").autocomplete({
        source: CountyArray,
        /*
        width: 170,
        matchContains: false,
        selectFirst: false
        */
        select: function(event, data) {
            if($("#county").val()!=''){
                $("#place").val('');
                $("#street").val('');
                $('#islike').val('0');
                LoadPlaceListNew(0);
            }
        }
    });

$("#street").autocomplete({
    source: siteURL+"auto_street.php?county="+county+"&county="+county,
    /*
    width: 260,
    selectFirst: false
    */
    select: function (event, ui) {
        var strit = ui.item.value;
        strit = strit.split(" (")[0];
        if (ui.item && ui.item.value){
            titleinput = ui.item.value;
            $("#street").val(strit);
            ui.item.value= $.trim(strit);
        } 
        if($("#street").val()!=''){ 
            LoadZipcodesNew(0);
        }
    }   
});