使用jQuery的autocomplete实现联想查询

jquery-3.2.1.min.js 、jquery-ui.min.js 、jquery-ui.css

 $("#dwmc").autocomplete({
      source: function( request, response ) {
        var dwmcCode1 = $("#dwmcCodeArg").val();
        var ishzyx = $("#ishzyx").val();
       //if(ishzyx && ishzyx.indexOf("否")==-1 && dwmcCode1 && dwmcCode1.indexOf("其它")==-1 ){
       if( dwmcCode1 && dwmcCode1.indexOf("其它")==-1 ){
         var term = request.term;
         $.ajax({
                        url:  rootPath+"/sign/toSignSearch.html?time="+new Date().getTime()+"&searchParam="+encodeURI(encodeURI(term))+"&searchParamType="+encodeURI(encodeURI(dwmcCode1)),
                        dataType: "json",
                        success: function( data ) {
                           response( $.map( data, function( item ) {
                                return {
                                    value: item.name
                            }
                            }));
                        }
                })
          }      
        },
       minLength: 1,
       select: function( event, ui ) {
         $("#dwmc").val(ui.item.value);
       }
    });

 

posted @ 2019-05-09 15:23  石洋  阅读(557)  评论(0编辑  收藏  举报