2013-07-28 14 views
0

我正在嘗試使用Ajax工具包實現自動完成列表:AutoCompleteExtender如何實現AutoCompleteExtender OnclientPopulated行爲?

如何使用Ajax工具包實現以下行爲:AutoCompleteExtender? 也可以提供任何代碼示例嗎?

  • 與谷歌搜索一樣,當自動完成列表顯示時,如果顯示基於輸入。當鼠標移出或聚焦在其他區域時。自動完成列表仍以輸入值爲基礎顯示。

  • 如果用戶輸入abc和系統顯示autocompletelist如abcd,abcde。當用戶移動鼠標,然後再次點擊時,相同的輸入abc系統應該再次顯示自動完成列表。

任何人都可以建議嗎?

回答

1

我個人更喜歡使用jQuery UI Autocomplete。

演示&代碼:

jQuery UI Autocomplete

樣品JS代碼:

$(function() { 
    function log(message) { 
     $("<div>").text(message).prependTo("#log"); 
     $("#log").scrollTop(0); 
    } 
    $("#city").autocomplete({ 
     source: function(request, response) { 
      $.ajax({ 
       url: "http://ws.geonames.org/searchJSON", 
       dataType: "jsonp", 
       data: { 
        featureClass: "P", 
        style: "full", 
        maxRows: 12, 
        name_startsWith: request.term 
       }, 
       success: function(data) { 
        response($.map(data.geonames, function(item) { 
         return { 
          label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName, 
          value: item.name 
         } 
        })); 
       } 
      }); 
     }, 
     minLength: 2, 
     select: function(event, ui) { 
      log(ui.item ? 
      "Selected: " + ui.item.label : 
      "Nothing selected, input was " + this.value); 
     }, 
     open: function() { 
      $(this).removeClass("ui-corner-all").addClass("ui-corner-top"); 
     }, 
     close: function() { 
      $(this).removeClass("ui-corner-top").addClass("ui-corner-all"); 
     } 
    }); 
}); 
0

你的第一點是Ajax的ACE(自動完成擴展)的默認行爲。

第二個,您可以使用jquery .mouseleave().mouseenter()事件來剃掉鼠標離開時隱藏字段中的contextKey,並在鼠標輸入中重新填充它。

相關問題