Jquery Ui AutoComplete auto-fill function

Jquery and jquery ui version used in the following:

jQuery v1.12.4

jQuery UI - v1.11.0

Some versions there will be some kinds of problems, not go into specific reasons.

jquery code is as follows

$("#id_customer").autocomplete({
            source:function (request,response) {
               var findResult = [];
               $.ajax({
                   url:"/ips/get_customername_list/",
                   data:{"term":request.term},
                   type:'GET',
                   success:function(data){
                       data = JSON.parse(data);
                       console.log(data);
                       var search_cus = request.term;
                       findResult = $.grep(data,function(value,index){
                           return value.indexOf(search_cus) > -1;
                       });
                       response(data);
                   }
               });
           }
        })

ajax to obtain background data

Background returns an array of data format is: [ 'data1', 'data2', 'data3' ........ 'data100']

Some need to modify the css styles, specific adjustments depending on your situation:

.ui-menu {
 width: 100px;
 list-style: none;
    margin-left: -50px;
    padding-left:0px ;
}
.ui-menu  .ui-menu-item{
    background-color: #fff;
    height: 25px;
    line-height: 25px;
    text-indent: 10px;
}
.ui-menu  .ui-menu-item:hover{
    color:#fff;
    background-color: #1b6d85;
}
.ui-menu .ui-state-focus{
    color:#fff;
    background-color: #1b6d85;
}

 

Guess you like

Origin www.cnblogs.com/pyghost/p/11016608.html