2014-02-07 82 views
0

我已經在文本框中使用了自動完成功能,但爲了獲取更多的數據,它會佔滿整個頁面,我想給它滾動條和高度。如何給滾動條,高度自動完成顯示列表?

這裏是我的代碼:

$(document).ready(function() { 

    $("#<%LkTxt.ClientID %>").autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       url: '<%=ResolveUrl("~/ETAWebService.asmx/GetLookUp") %>', 
       data: "{ 'prefix': '" + request.term + "'}", 
       dataType: "json", 
       type: "POST", 
       scroll: true, 
       scrollHeight: 180, 
       contentType: "application/json; charset=utf-8", 
       success: function (data) { 
        response($.map(data.d, function (item) { 
         return { 
          label: item.split('-')[0], 
          val: item.split('-')[1] 
         } 
        })) 
       }, 
       error: function (response) { 
        alert(response.responseText); 
       }, 
       failure: function (response) { 
        alert(response.responseText); 
       } 
      }); 
     }, 
     select: function (e, i) { 
      $("#<%=CmbHdn.ClientID %>").val(i.item.val); 
     }, 
     minLength: 1 
    }); 
}); 

</script> 

回答

2

很簡單,只是重寫CSS!

ul.ui-autocomplete { max-height: 350px !important; overflow: auto !important; } 
0

你正在應用自動完成的文本框把它放在一個div中爲該div定義一個類,並在其上應用css。

實施例 -

<style> 
.ui-autocomplete { 
    max-height: 100px; 
    overflow-y: auto; 
    overflow-x: hidden; 

    padding-right: 20px; 
} 
html .ui-autocomplete { 
    height: 100px; 
} 
</style> 

<div class="ui-autocomplete"> 
    <input type="text" id="search" name="search" /> 
</div>